Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apisauce

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apisauce

A JSON API client for JavaScript. No, no. Not like that. Like this.

  • 0.5.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is apisauce?

Apisauce is a library that simplifies the process of making HTTP requests in JavaScript applications. It is built on top of the popular axios library and provides a cleaner and more intuitive API for handling API requests and responses.

What are apisauce's main functionalities?

Creating an API instance

This feature allows you to create an API instance with a base URL and default headers. This instance can then be used to make various HTTP requests.

const { create } = require('apisauce');

const api = create({
  baseURL: 'https://api.example.com',
  headers: { Accept: 'application/json' },
});

Making GET requests

This feature allows you to make GET requests to the specified endpoint. The response object contains useful information such as the data, status, and any problems encountered.

api.get('/users').then(response => {
  if (response.ok) {
    console.log(response.data);
  } else {
    console.error(response.problem);
  }
});

Making POST requests

This feature allows you to make POST requests with a payload. The response object can be used to handle the result of the request.

api.post('/users', { name: 'John Doe', email: 'john.doe@example.com' }).then(response => {
  if (response.ok) {
    console.log(response.data);
  } else {
    console.error(response.problem);
  }
});

Setting request and response transforms

This feature allows you to add transforms to requests and responses. Request transforms can modify the request before it is sent, and response transforms can modify the response before it is processed.

api.addRequestTransform(request => {
  request.headers['Authorization'] = 'Bearer token';
});

api.addResponseTransform(response => {
  if (!response.ok) {
    response.data = { error: 'Something went wrong' };
  }
});

Other packages similar to apisauce

Keywords

FAQs

Package last updated on 28 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc