1.0.1-24.0 • Published 5 years ago

fetches v1.0.1-24.0

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

fetches

codecov CircleCI Greenkeeper badge

Fetches is a workaround to make requests, in an easy and scalable way.

With Fetches you can define your main settings (URL, Auth Header, Request Type, etc), in a single place and then make requests using this info.

Table of Contents

Install

npm install --save fetches

Example

Here we will show a simple request to pokeapi, getting the first pokemon.

import { createClient, getHTTPMethods } from 'fetches'

const client = createClient('http://pokeapi.co/api/v2/')

const http = getHTTPMethods(client)

const bulbasaur = await http.get('pokemon/1') 

API Reference

Client instance

Methods

  • getURI - returns the URI of client.

Function createClient

Syntax

(uri, [options]) => Client

Import

import { createClient } from 'fetches'

Parameters

  • uri - The URI of your API.
  • options - optional - An object containing the settings for all requests made by this created client.
    • request - default: {} - The same custom settings accepted by fetch
    • uri - default: { removeTrailingSlash: false } - The same setting accepted by sindresorhus/normalize-url

Function getHTTPMethods

Syntax

(client) => Object

Import

import { getHTTPMethods } from 'fetches'

HTTP Methods

  • get(uri, [params, options])

    • uri - String, Array\<String> - the complement of your main URI.
    • params - Object - optional - URL query params.
    • options - Object - optional - The same custom settings accepted by fetch
  • post(uri, [params, options])

    • uri - String, Array\<String> - the complement of your main URI.
    • data - Object - optional - The body of request.
    • options - Object - optional - The same custom settings accepted by fetch
  • put(uri, [params, options])

    • uri - String, Array\<String> - the complement of your main URI.
    • data - Object - optional - The body of request.
    • options - Object - optional - The same custom settings accepted by fetch
  • patch(uri, [params, options])

    • uri - String, Array\<String> - the complement of your main URI.
    • data - Object - optional - The body of request.
    • options - Object - optional - The same custom settings accepted by fetch
  • delete(uri, [params, options])

    • uri - String, Array\<String> - the complement of your main URI.
    • data - Object - optional - The body of request.
    • options - Object - optional - The same custom settings accepted by fetch

Browser Support

Fetches is based on Fetch API, which the most of modern browsers already are compatible, but if you need to be compatible with an older browser, you may use this polyfill

How to Contribute

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -m 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :)

License

MIT License

Copyright (c) 2018 Daniel Leite de Oliveira

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

1.0.1-24.0

5 years ago

1.0.1-23.0

5 years ago

1.0.1-22.0

5 years ago

1.0.1-21.0

5 years ago

1.0.1-20.0

5 years ago

1.0.1-19.0

5 years ago

1.0.1-18.0

5 years ago

1.0.1-16.0

5 years ago

1.0.1-14.0

5 years ago

1.0.1-13.0

5 years ago

1.0.1-12.0

5 years ago

1.0.1-11.0

5 years ago

1.0.1-10.0

5 years ago

1.0.1-9.0

5 years ago

1.0.1-8.0

5 years ago

1.0.1-7.0

5 years ago

1.0.1-6.0

5 years ago

1.0.1-5.0

5 years ago

1.0.1-4.0

6 years ago

1.0.1-3.0

6 years ago

1.0.1-2.0

6 years ago

1.0.1-1.0

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.1.0-alpha.5

6 years ago

0.1.0-alpha.4

6 years ago

0.1.0-alpha.3

6 years ago

0.1.0-alpha.2

6 years ago

0.1.0-alpha.1

6 years ago

0.1.0-alpha.0

6 years ago