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

gaxios

Package Overview
Dependencies
Maintainers
0
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gaxios

A simple common HTTP client specifically for Google APIs and services.

  • 6.7.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13M
decreased by-0.01%
Maintainers
0
Weekly downloads
 
Created

What is gaxios?

The gaxios npm package is a lightweight HTTP client based on Axios but with a smaller footprint. It is designed to work in both browser and node environments, providing a simple way to make HTTP requests. It supports all HTTP request methods, automatic JSON data transformation, and custom configuration for requests.

What are gaxios's main functionalities?

GET Request

This feature allows you to make GET requests to retrieve data from a specified resource.

const { request } = require('gaxios');

async function getUser() {
  try {
    const response = await request({ url: 'https://api.example.com/user', method: 'GET' });
    console.log(response.data);
  } catch (error) {
    console.error(error);
  }
}

getUser();

POST Request

This feature allows you to make POST requests to send data to a server to create/update a resource.

const { request } = require('gaxios');

async function createUser(userData) {
  try {
    const response = await request({
      url: 'https://api.example.com/user',
      method: 'POST',
      data: userData
    });
    console.log(response.data);
  } catch (error) {
    console.error(error);
  }
}

createUser({ name: 'New User', email: 'newuser@example.com' });

Interceptors

Interceptors allow you to run your code or modify the request and/or response before the request is sent or after the response is received.

const { Gaxios } = require('gaxios');

const instance = new Gaxios({
  baseURL: 'https://api.example.com'
});

// Add a request interceptor
instance.interceptors.request.use(config => {
  // Do something before request is sent
  config.headers['Authorization'] = 'Bearer token';
  return config;
});

// Add a response interceptor
instance.interceptors.response.use(response => {
  // Do something with response data
  return response;
}, error => {
  // Handle error
  return Promise.reject(error);
});

Custom Configuration

Custom configuration allows you to specify various options for the HTTP request, such as headers, query parameters, timeout, and more.

const { request } = require('gaxios');

async function getCustomData() {
  try {
    const response = await request({
      url: 'https://api.example.com/data',
      method: 'GET',
      timeout: 5000,
      headers: { 'X-Custom-Header': 'foobar' }
    });
    console.log(response.data);
  } catch (error) {
    console.error(error);
  }
}

getCustomData();

Other packages similar to gaxios

Keywords

FAQs

Package last updated on 27 Jun 2024

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