JSPM

  • Created
  • Published
  • Downloads 264
  • Score
    100M100P100Q90507F
  • License MIT

Package Exports

  • @salus-js/http-client
  • @salus-js/http-client/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@salus-js/http-client) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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.