https://github.com/scmmishra/pup
A tiny (> 1kb) pupper that fetches for you
https://github.com/scmmishra/pup
ajax browser fetch rest rest-api tiny
Last synced: 11 days ago
JSON representation
A tiny (> 1kb) pupper that fetches for you
- Host: GitHub
- URL: https://github.com/scmmishra/pup
- Owner: scmmishra
- License: mit
- Created: 2023-03-13T09:07:47.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-12T11:27:18.000Z (over 3 years ago)
- Last Synced: 2026-02-17T19:43:36.710Z (5 months ago)
- Topics: ajax, browser, fetch, rest, rest-api, tiny
- Language: TypeScript
- Homepage:
- Size: 1.09 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
pup-fetch



A tiny (370B) pupper that fetches for you, pup is a slim wrapper around fetch
## Installation
```sh
pnpm install pup-fetch
```
```sh
npm install pup-fetch
```
```sh
yarn install pup-fetch
```
## Usage
Import the methods you need from the module:
```js
import { get, post } from "pup-fetch";
```
### GET Requests
Make a GET request using the get method:
```ts
const response = await get("/api/my-endpoint");
```
The `get` method takes two arguments: the `path` to the endpoint and an optional configuration object. The configuration object can include a `baseUrl` property to specify a base URL to prepend to the endpoint path.
### POST Requests
Make a POST request using the post method:
```ts
const body = { name: "John Doe", email: "john.doe@example.com" };
const response = await post("/api/my-endpoint", body);
```
The `post` method takes three arguments: the `path` to the endpoint, the request `body`, and an optional configuration object. Like with `get`, the configuration object can include a `baseUrl` property.
### Configuration
The `RequestConfig` interface defines the configuration options for HTTP requests. The following properties are available:
- `baseUrl`: The base URL to prepend to the endpoint path.
- `method`: The HTTP method to use (e.g. GET, POST, PUT, DELETE).
- `headers`: An object containing HTTP headers to include in the request.
- `body`: The request body, as a string or an object that can be serialized to JSON.
- `mode`: The request mode, which can be "cors", "no-cors", "same-origin", or "navigate".
- `cache`: The cache mode, which can be "default", "no-store", "reload", "no-cache", "force-cache", or "only-if-cached".
- `redirect`: The redirect mode, which can be "follow", "error", or "manual".