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

ofetch

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ofetch

Add optinal type-safety to your function calls.

  • 0.2.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
993K
decreased by-16.21%
Maintainers
1
Weekly downloads
 
Created

What is ofetch?

ofetch is a modern, lightweight HTTP client for making network requests in JavaScript. It is designed to be simple and easy to use, while providing powerful features for handling HTTP requests and responses.

What are ofetch's main functionalities?

Basic GET Request

This feature allows you to make a basic GET request to a specified URL and handle the response. The response data is logged to the console.

const { $fetch } = require('ofetch');

(async () => {
  const data = await $fetch('https://api.example.com/data');
  console.log(data);
})();

POST Request with JSON Body

This feature allows you to make a POST request with a JSON body. The response data is logged to the console.

const { $fetch } = require('ofetch');

(async () => {
  const data = await $fetch('https://api.example.com/data', {
    method: 'POST',
    body: JSON.stringify({ key: 'value' })
  });
  console.log(data);
})();

Custom Headers

This feature allows you to add custom headers to your HTTP requests. The response data is logged to the console.

const { $fetch } = require('ofetch');

(async () => {
  const data = await $fetch('https://api.example.com/data', {
    headers: {
      'Authorization': 'Bearer token',
      'Content-Type': 'application/json'
    }
  });
  console.log(data);
})();

Handling Errors

This feature demonstrates how to handle errors that may occur during an HTTP request. If an error occurs, it is caught and logged to the console.

const { $fetch } = require('ofetch');

(async () => {
  try {
    const data = await $fetch('https://api.example.com/data');
    console.log(data);
  } catch (error) {
    console.error('Error:', error);
  }
})();

Other packages similar to ofetch

Keywords

FAQs

Package last updated on 03 May 2022

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