0.16.0 • Published 2 years ago

@salus-js/http-client v0.16.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Intro

A library for making type-safe HTTP requests built on the popular Axios client.

Usage

@salus-js/http-client builds on @salus-js/codec and @salus-js/http to make runtime type-checked HTTP requests a breeze. Let's run through a quick sample:

import { t } from '@salus-js/codec'
import { http } from '@salus-js/http'
import { AxiosClient } from '@salus-js/http-client'

const todoResource = t.object({
  userId: t.number,
  id: t.number,
  title: t.string,
  completed: t.boolean
})

const todoParams = t.object({
  id: t.number
})

const getTodo = http.get('/todos/:id', {
  params: todoParams,
  response: todoResource
})

const client = AxiosClient.create('https://jsonplaceholder.typicode.com/')

const responsePromise = client.execute(getTodo, {
  params: {
    id: 1
  }
})

responsePromise.then((response) => {
  console.log(response.data)
})

Guide

Client Instance

When creating a new instance of the Salus Axios client, you need to specify a default baseURL. This URL will be prepended to all paths defined in your operations. Note that you are able to override the baseURL for a specific request.

0.16.0

2 years ago

0.15.1

2 years ago

0.15.0

2 years ago

0.14.1

2 years ago

0.14.0

2 years ago

0.13.0

2 years ago

0.12.2

2 years ago

0.11.3

2 years ago

0.11.4

2 years ago

0.11.0

3 years ago

0.10.3

3 years ago

0.10.2

3 years ago

0.10.0

3 years ago

0.9.3

3 years ago

0.9.1

3 years ago

0.8.0

3 years ago

0.7.9

3 years ago

0.7.8

3 years ago

0.7.7

3 years ago

0.7.6

3 years ago

0.7.5

3 years ago

0.7.4

3 years ago

0.7.3

3 years ago

0.7.2

3 years ago

0.7.1

3 years ago

0.7.0

3 years ago

0.6.0

3 years ago

0.5.9

3 years ago

0.5.8

3 years ago

0.5.7

3 years ago

0.5.4

3 years ago

0.5.3

3 years ago

0.5.6

3 years ago

0.5.5

3 years ago

0.5.2

3 years ago

0.5.0

3 years ago

0.4.0-alpha.0

3 years ago

0.3.0-alpha.0

3 years ago