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 - npm Package Compare versions

Comparing version 1.2.1 to 1.3.0

dist/shared/ofetch.67cb96a4.mjs

4

dist/index.d.ts

@@ -1,3 +0,3 @@

import { $ as $Fetch } from './shared/ofetch.f39fffc1.js';
export { C as CreateFetchOptions, b as FetchContext, e as FetchError, c as FetchOptions, F as FetchRequest, a as FetchResponse, S as SearchParameters, d as createFetch, f as createFetchError } from './shared/ofetch.f39fffc1.js';
import { $ as $Fetch } from './shared/ofetch.7eda91bf.js';
export { C as CreateFetchOptions, b as FetchContext, e as FetchError, c as FetchOptions, F as FetchRequest, a as FetchResponse, S as SearchParameters, d as createFetch, f as createFetchError } from './shared/ofetch.7eda91bf.js';

@@ -4,0 +4,0 @@ declare const fetch: typeof globalThis.fetch;

@@ -1,3 +0,3 @@

import { $ as $Fetch } from './shared/ofetch.f39fffc1.js';
export { C as CreateFetchOptions, b as FetchContext, e as FetchError, c as FetchOptions, F as FetchRequest, a as FetchResponse, S as SearchParameters, d as createFetch, f as createFetchError } from './shared/ofetch.f39fffc1.js';
import { $ as $Fetch } from './shared/ofetch.7eda91bf.js';
export { C as CreateFetchOptions, b as FetchContext, e as FetchError, c as FetchOptions, F as FetchRequest, a as FetchResponse, S as SearchParameters, d as createFetch, f as createFetchError } from './shared/ofetch.7eda91bf.js';

@@ -4,0 +4,0 @@ declare function createNodeFetch(): (input: RequestInfo, init?: RequestInit) => any;

{
"name": "ofetch",
"version": "1.2.1",
"version": "1.3.0",
"description": "A better fetch API. Works on node, browser and workers.",

@@ -79,2 +79,3 @@ "repository": "unjs/ofetch",

"prettier": "^3.0.2",
"std-env": "^3.4.3",
"typescript": "^5.1.6",

@@ -81,0 +82,0 @@ "unbuild": "2.0.0",

@@ -70,4 +70,12 @@ # ofetch

`ofetch` automatically stringifies request body (if an object is passed) and adds JSON `Content-Type` and `Accept` headers (for `put`, `patch` and `post` requests).
If an object or a class with a `.toJSON()` method is passed to the `body` option, `ofetch` automatically stringifies it.
`ofetch` utilizes `JSON.stringify()` to convert the passed object. Classes without a `.toJSON()` method have to be converted into a string value in advance before being passed to the `body` option.
For `PUT`, `PATCH`, and `POST` request methods, when a string or object body is set, `ofetch` adds the default `content-type: "application/json"` and `accept: "application/json"` headers (which you can always override).
Additionally, `ofetch` supports binary responses with `Buffer`, `ReadableStream`, `Stream`, and [compatible body types](https://developer.mozilla.org/en-US/docs/Web/API/fetch#body). ofetch will automatically set the `duplex: "half"` option for streaming support!
**Example:**
```js

@@ -87,4 +95,4 @@ const { users } = await ofetch("/api/users", {

```ts
await ofetch("http://google.com/404");
// FetchError: 404 Not Found (http://google.com/404)
await ofetch("https://google.com/404");
// FetchError: [GET] "https://google/404": 404 "Not Found"
// at async main (/project/playground.ts:4:3)

@@ -120,3 +128,3 @@ ```

You can specifcy amount of retry and delay between them using `retry` and `retryDelay` options.
You can specifcy amount of retry and delay between them using `retry` and `retryDelay` options and also pass a custom array of codes using `retryStatusCodes` option.

@@ -123,0 +131,0 @@ Default for `retry` is `1` retry, except for `POST`, `PUT`, `PATCH` and `DELETE` methods where `ofetch` does not retry.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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