url-request
The most advanced HTTP Client and Url Builder with Functional Chaining, Async/Await, Delay, Fork, Infinite Chaining and Repeat for building your Complex APIs easily.
Alternative to Requests, Axios, and Got.
Installation
npm install url-request --save
Initialize
const Url =
Examples
Look Examples
Repeat
Building a Ping server was never as easy! This pings at an interval of 1s and let's you know if you're connected or not.
// time 1000ms
GET Request w/ Promise
Send a GET request with an access token, then display the result or catch errors.
GET https://my-json-server.typicode.com/typicode/demo/posts/comments
// GET Request
id: 1 post: 'Post 1' id: 2 post: 'Post 2'
Build A Complex Url
Build Complex Urls with deep paths, multiple queries (lists are supported) and fragments.
const url = url // https://api.workpay.com//rooms/open/users?id=10,12,13,14&// access_token=my-token&password=password#bio
Invoke / Execute
// To Get Full Response Object
Fork
const userApi = const subscriptionsApi = userApi const achievementsApi = userApi userApi subscriptionsApi achievementsApi
POST Request w/ Promise
A POST request with a body { subscrbe: 'Apple Music' }
at https://api.workpay.com/user/123#subscriptions
// { success: true }
Async/Await
const post = async { const request = return await request}
Delay
Delay your requests!
Infinite Chain
... // Keep on going!
Functions
// Url Construction // Start with the baseUri go (...paths) // Go to Sub Path query (q) // q is query object fragment (f) // add fragments like #profile // Fork fork () // default encoding is 'json', can be null, 'string', 'buffer' encodeResponse (encoding) // Set headers header (headers) // get the formed url as a string get url () // Requests get (body, statusCode) // GET Request post (body, statusCode) // POST Request put (body, statusCode) // PUT Request delete (body, statusCode) // DELETE Request patch (body, statusCode) // PATCH Request then (func) catch (func) finally (func) delay (time, func) repeat (time, count) // Command Control, Lazy Execution invoke (command, ...args) execute (invokeCommands)}
Upcoming
- OAuth
- HTTP2
- Proxy
- Compression
- Timeout Handling
- Custom Hooks
- Request Cancellation