dotfetch
v1.2.0
Published
Dot-notated api wrapper for the browser fetch function.
Downloads
2
Maintainers
Readme
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()