1.0.2 • Published 1 year ago

letch v1.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

A local fetch for the times you don't need a server.

Installation

CDN

import {letch} from "https://cdn.jsdelivr.net/npm/letch"
<!-- Import maps polyfill -->
<!-- Remove this when import maps will be widely supported -->
<script async src="https://unpkg.com/es-module-shims@1.3.6/dist/es-module-shims.js"></script>

<script type="importmap">
    {
        "imports": {
            "letch": "https://cdn.jsdelivr.net/npm/letch"
        }
    }
</script>

Usage

import {letch} from "letch"

letch('/users', { method: 'POST', body: { user: 'john' } })
letch('/users/1', { method: 'PUT', body: { user: 'john' } })
letch('/users/2', { method: 'PUT', body: { user: 'marry' } })
letch('/products/1', { method: 'PUT', body: { name: 'product 1', price: 1 } })
letch('/products/2', { method: 'PUT', body: { name: 'product 2', price: 1 } })
console.table(letch('/products'))
console.table(letch('/users'))
letch('/products/1', { method: 'DELETE' })

// Batch delete
letch('/users', { method: 'GET' }).forEach(element => {
    letch(`/users/${element.id}`, {method: 'DELETE'})
});
console.table(letch('/users'))