npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

url-request

v1.0.13

Published

A HTTP Client and Url Builder with Functional Chaining, Async/Await and Fork.

Downloads

6

Readme

url-request

Generic badge Generic badge Generic badge Generic badge

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 = require('url-request')

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.

Url('https://postman-echo.com/get')
  .get()
  .then(() => console.log('Ping Successful! Internet is up 🤟')) 
  .catch(() => console.log('Ping Failed! Internet is down 😭'))
  .repeat(1000, 100) // 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

Url('https://my-json-server.typicode.com')
  .go('typicode/demo')
  .go('posts')
  .query({ access_token: 'MyAccessToken' })
  .get() // GET Request
  .then(json => console.log(json)) 
  .catch(err => console.error('[Error]', err))
[{ 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')
  .go('rooms', 'open', 'users')
  .query({ id: [10, 12, 13, 14] })
  .query({ access_token: 'my-token', password: 'password'})
  .fragment('bio')
  .url
  
// https://api.workpay.com//rooms/open/users?id=10,12,13,14&
// access_token=my-token&password=password#bio

Invoke / Execute

Url('https://postman-echo.com')
  .invoke('go', 'post')
  .invoke('encodeResponse', null) // To Get Full Response Object
  .invoke('post', { foo1: 'bar1', foo2: 'bar2' })
  .execute()
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error(err))

Fork

const userApi = Url('https://api.workpay.com')
  .go('user', 123)

const subscriptionsApi = userApi
  .fork()
  .fragment('subscriptions')

const achievementsApi = userApi
  .fork()
  .fragment('achievements')

[ userApi, subscriptionsApi, achievementsApi ]
  .forEach(api => api
    .then(json => console.log(json))
    .catch(err => console.log(err)))

POST Request w/ Promise

A POST request with a body { subscrbe: 'Apple Music' } at https://api.workpay.com/user/123#subscriptions

Url('https://api.workpay.com')
  .go('user', 123)
  .fragment('subscriptions')
  .post({ subscrbe: 'Apple Music' })
  .then(json => console.log(json)) // { success: true }
  .catch(err => console.error(err))

Async/Await

const post = async () => {
  const request = Url('https://postman-echo.com')
    .go('post')
    .post({ foo1: 'bar1', foo2: 'bar2' })
  
  return await request
}

Delay

Delay your requests!

Url('https://postman-echo.com/post')
  .delay(2000, () => console.log('Wait 2s'))
  .post({ foo1: 'bar1', foo2: 'bar2' })

Infinite Chain

See Infinite Chain Example

Url('https://my-json-server.typicode.com')
  .go('typicode/demo')
  .go('posts')
  .get()
  .then(json => console.log('[1]', json)) 
  .catch(err => console.error('[Error]', err))
  .go(1)
  .get()
  .then(json => console.log('[2]', json)) 
  .catch(err => console.error('[Error]', err))
  .post()
  .post()
  ... // Keep on going!

Functions

class Url {

  // Url Construction
  constructor (baseUri) // 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