Example #1
0
        public void RegisterWithApiHandler(BloomApiHandler apiHandler)
        {
            apiHandler.RegisterEndpointHandler(kApiUrlPart + "list", HandleListRequest, true);

            apiHandler.RegisterEndpointHandler(kApiUrlPart + "name", request =>
            {
                // always null? request.ReplyWithText(_collection.Name);
                request.ReplyWithText(_settings.CollectionName);
            }, true);

            apiHandler.RegisterEndpointHandler(kApiUrlPart + "books", HandleBooksRequest, true);
            apiHandler.RegisterEndpointHandler(kApiUrlPart + "book", HandleThumbnailRequest, true);

            apiHandler.RegisterEndpointHandler(kApiUrlPart + "selected-book-id", request =>
            {
                switch (request.HttpMethod)
                {
                case HttpMethods.Get:
                    request.ReplyWithText("" + _libraryModel.GetSelectedBookOrNull()?.ID);
                    break;

                case HttpMethods.Post:
                    var book = GetBookObjectFromPost(request);
                    _libraryModel.SelectBook(book);
                    request.PostSucceeded();
                    break;
                }
            }, true);
        }