Sophie HTTP
Provides simple components for creating http requests. Ideal for an API. It uses Promises.
Part of the framework Sophie
INSTALLATION
yarn add sophie-http
USAGE
QUERY
To make a GET request use the Query object
// Import objects; // Instantiate Query; // Set the API endpointquery.setUrl'api/posts'; // Make the request, returns a Promisequery.getDatanew HtmlRequestContentType .then .catch;
COMMAND
To make a POST, PUT or DELETE request use the Command object
// Import objects; // Instantiate Command; // Set the API endpointcommand.setUrl'api/posts'; command.saveDatanew JsonRequestContentType, .then .catch; command.updateDatanew JsonRequestContentType, .then .catch; command.deleteDatanew JsonRequestContentType, .then .catch;
Extending Query or Command
For example, to pre-set the url
// Import objects; ; ;; postsQuery.getDatanew JsonRequestContentType .then .catch; postsCommand.saveDatanew JsonRequestContentType, .then .catch; postsCommand.updateDatanew JsonRequestContentType, .then .catch; postsCommand.deleteDatanew JsonRequestContentType, .then .catch;
Changelog
Contributing
License
This software is licensed under the terms of the MIT license. See LICENSE for the full license.