npm i noutaa
import { GET, POST } from 'noutaa'
let sweets = await GET(`/cafe`, {
accept: 'json'
})
console.log(sweets) // ['cookies', 'cake']
const res = await POST(`/new-cafe`, {
json: sweets
})
console.log(res) // Response object
import { GET, POST, PUT, PATCH, HEAD, DELETE } from 'noutaa'
GET(`/beer`) // just a normal Promise/Response object
Add or merge query string parameters without playing with strings.
// GET /beer?strength=5
GET(`/beer`, {
params: { strength: 5 }
})
// GET /beer?strength=5&price=free
GET(`/beer?strength=5`, {
params: { price: 'free' }
})
// with noutaa
const res = await POST(`/nudes`, {
json: { url: 'http://gph.is/1oo2GZg' }
})
// without noutaa
const res = await fetch(`/nudes`, {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
body: JSON.stringify({ url: 'http://gph.is/1oo2GZg' })
})
// with noutaa
const res = await POST(`/form`, {
urlencoded: { message: 'hello' }
})
// without noutaa
const body = new URLSearchParams()
body.append('message', 'hello')
const res = await fetch(`/form`, {
method: 'POST',
body,
headers: {
'application/x-www-form-urlencoded'
}
})
All response statuses that are not OK are thrown as HTTPError.
res.ok
are all status codes in 200s range.
try {
await DELETE(`/beer/999`);
} catch (error) {
switch (error.code) {
case '403': console.log(`You shalt not pass!`) break;
case '404': console.log(`You missed!`) break;
default: return;
}
}
- Hooks
- Authentication header for easy JWT
form-data