Skip to content

ruslankonev/dotfetch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dot-notated api wrapper for the browser Fetch API.

Install

npm i dotfetch

Setup

import Dotfetch from 'dotfetch'

const api = new Dotfetch({
  basePath: 'https://jsonplaceholder.typicode.com/',
  parseJson: true,
  headers: {
    Authorization: 'Bearer ',
  },
})

Options

Dotfetch options:

basePath: string — setup a base path for api-call

parseJson: boolean — return response.json() instead Response object. Default false

Fetch API options:

Dotfetch supports all standard Fetch API options.

Return value

Fetch API Response object

Examples

[api][...path][method](params)


// Make api-call request
GET: '/application/{appId}/permissions/{id}'
await api.application(appId).permissions.get(id)

// JSON-placeholder examples
GET: '/posts'
await api.posts.get()

GET: '/posts/1/comments'
await api.posts(1).comments.get()

GET: '/posts/comments/1'
await api.posts.comments.get(1)

POST: '/posts/comments'
await api.posts.comments.post({ title, postId })

PUT: '/posts/1'
await api.posts(1).put({ title, postId })

PATCH: '/posts/1'
await api.posts(1).patch({ title, postId })

DELETE: '/posts/1'
await api.posts(1).delete()

License

MIT

About

Dot-notated api wrapper over fetch

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published