Skip to content

Commit

Permalink
docs: add TOC and request cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
fzn0x committed Jul 15, 2024
1 parent 450a5dc commit a8f7a0e
Showing 1 changed file with 42 additions and 34 deletions.
76 changes: 42 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<img width="55%" src="./assets/hyperfetch.png">
</p>

> :warning: Hypf still in early-stage, so any sudden breaking changes is expected
<hr />

[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/fzn0x/hypf/ci.yml?branch=main)](https://github.com/fzn0x/hypf/actions)
Expand All @@ -22,6 +20,22 @@ Small (6.3kB minified & 0 dependencies) and type-powered HTTP client for Deno, B

The most flexible fetch wrapper that allows you to have more than one practice to get things done!

## Table of Contents

- [Get Started](#get-started)
- [Error Handling](#error-handling)
- [Response Cloning](#response-cloning)
- [Request Cloning](#request-cloning)
- [Hooks](#hooks)
- [Retry Mechanism](#retry-mechanism)
- [Infer Response Types](#infer-response-types)
- [URLSearchParams](#urlsearchparams)
- [Form Data](#form-data)
- [AbortController](#abortcontroller)
- [Debug](#debug)
- [Acknowledgements](#acknowledgements)
- [License](#license)

## Get Started

```sh
Expand Down Expand Up @@ -145,49 +159,43 @@ try {
You need to use `throwOnError: true` to enable Response clone feature.

```ts
try {
const res = await createRequest(
'https://jsonplaceholder.typicode.com/todos/1',
{},
{},
{
throwOnError: true,
}
)
const res = await createRequest(
'https://jsonplaceholder.typicode.com/todos/1',
{},
{},
{
throwOnError: true,
}
)

const response2 = res.clone()
const response2 = res.clone()

expect(res).to.be.an.instanceOf(Response)
expect(response2).to.be.an.instanceOf(Response)
expect(await res.json()).to.be.an.instanceOf(Object)
expect(await response2.json()).to.be.an.instanceOf(Object)
} catch (err) {
console.log(err)
}
expect(res).to.be.an.instanceOf(Response)
expect(response2).to.be.an.instanceOf(Response)
expect(await res.json()).to.be.an.instanceOf(Object)
expect(await response2.json()).to.be.an.instanceOf(Object)
```

## Request Cloning

You need to use `throwOnError: true` and `dryRun: true` to enable Request clone feature.

```ts
try {
const req = await createRequest(
'https://jsonplaceholder.typicode.com/todos/1',
{},
{},
{
throwOnError: true,
}
)
const req = await createRequest(
'https://jsonplaceholder.typicode.com/todos/1',
{
dryRun: true,
},
{},
{
throwOnError: true,
}
)

const req2 = req.clone()
const req2 = req.clone()

expect(req).to.be.an.instanceOf(Request)
expect(req2).to.be.an.instanceOf(Request)
} catch (err) {
console.log(err)
}
expect(req).to.be.an.instanceOf(Request)
expect(req2).to.be.an.instanceOf(Request)
```

## Hooks
Expand Down

0 comments on commit a8f7a0e

Please sign in to comment.