Interacting with APIs β
Netzo provides a simple and intuitive way to interact with APIs. It allows you to create a client for an existing API or a custom API and provides a convenient way to make requests to the API.
The following basic examples show how to work with APIs.
Creating a client for a custom API β
An example of connecting to a custom API, in this case the JSONPlaceholder API.
jsx
import { createApi } from 'https://deno.land/x/[email protected]/mod.ts'
const api = createApi({
baseURL: 'https://jsonplaceholder.typicode.com',
headers: { 'content-type': 'application/json' }
})
const data = await api.sales.get({ start: Date.now() })
import { createApi } from 'https://deno.land/x/[email protected]/mod.ts'
const api = createApi({
baseURL: 'https://jsonplaceholder.typicode.com',
headers: { 'content-type': 'application/json' }
})
const data = await api.sales.get({ start: Date.now() })
Creating a client for an existing API β
An example of connecting to an existing API, in this case the JSONPlaceholder API.
jsx
import { jsonplaceholder } from 'https://deno.land/x/[email protected]/mod.ts'
const api = jsonplaceholder()
const users = await api.users.get()
import { jsonplaceholder } from 'https://deno.land/x/[email protected]/mod.ts'
const api = jsonplaceholder()
const users = await api.users.get()
You can visit the apis
page to see a list of all the APIs that are currently supported.
API configuration options
Note that different APIs might require different configuration options (see here for more information).