• Stars
    star
    147
  • Rank 245,505 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created 9 months ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Run and test your HTTP requests. Git friendly, 100% local.

Fetchbook npm version

Fetchbook is a command-line tool designed to help you manage your collections of HTTP requests. It is based on the standard RequestInit object, and runs in TypeScript with bun.sh.

You can try it out just by running this command:

npx fetchbook run --demo -v

Warning

πŸ‘·β€β™€οΈ Fetchbook is currently under active development, expect breaking changes.

Installation

To use Fetchbook in you own project:

npx fetchbook init

To create a separate Fetchbook project:

npx fetchbook init <project name>

Alternatively, you can install it manually:

npm install fetchbook

Usage

Fetchbook is split in different commands that operate on one or multiple fetch story files.

Run

fetchbook run [story] [options]

Run one or many fetch story files.

Demo

npx fetchbook run --demo -v

Arguments

  • [story] (optional): Path to a fetch story file (or folder) that describes an HTTP request. If omitted, Fetchbook will prompt you to search and choose a fetch story in the current folder.

Options

  • -a, --all: Run all fetch story files in the current folder recursively.
  • -v, --verbose: Enable verbose output, providing additional information about the request and response.
  • -d, --dry-run: Perform a dry run, simulating the request without making an actual HTTP call.

Examples

  1. Run a single fetch story file:

    fetchbook run path/to/your/story.fetch.ts
  2. Run all fetch story files in the current folder and its subfolders:

    fetchbook run -a
  3. Perform a dry run of a fetch story file:

    fetchbook run path/to/your/story.fetch.ts -d
  4. Run a fetch story file with verbose output:

    fetchbook run path/to/your/story.fetch.ts -v

Export

fetchbook export [story] [options]

Export a fetch story file as other formats (now only curl is supported) and display it in the terminal instead of making the HTTP request.

Demo

npx fetchbook export --format=curl --demo -a

Arguments

  • [story] (optional): Path to a fetch story file (or folder) that describes an HTTP request. If omitted, Fetchbook will prompt you to search and choose a fetch story in the current folder.

Options

  • -f, --format: Export the request as a cURL command and display it in the terminal instead of making the HTTP request.
  • -a, --all: Export all fetch story files in the current folder recursively.

Examples

  1. Export a single fetch story file as a cURL command:

    fetchbook export --format curl path/to/your/story.fetch.ts
  2. Export all fetch story files in the current folder and its subfolders:

    fetchbook export --format curl -a

Init

npx fetchbook init [name]

Initialize a fetchbook project.

Arguments

  • [name] (optional): Name of the project. If set Fetchbook will create a new folder with a package.json file and a bunch of sample fetch story files. If not set Fetchbook will initialize an existing project.

Examples

  1. Run a single fetch story file:

    npx fetchbook init my-fetchbook-project

Fetch Story Files

Fetch story files are TypeScript modules ending with .fetch.ts that must comply with the following type definition:

type FetchStory = {
  name: string;
  url: string;
  init: RequestInit;
  expect?: Partial<{
    status: number;
    statusText: string;
    headers: Record<string, string>;
    body: any;
  }>;
  before?: FetchStory[];
  after?: FetchStory[];
};

Here's an explanation of each property within the FetchStory type definition:

  • name (string): A descriptive name for the story, helping you identify and organize your requests.
  • url (string): The URL of the HTTP request.
  • init (RequestInit): An object containing the request's initialization options, including method, headers, and body.
  • expect (optional): Defines your expectations for the response, such as expected HTTP status code, status text, headers and body.
  • before (optional): An array of FetchStory objects representing requests to execute before the main request.
  • after (optional): An array of FetchStory objects representing requests to execute after the main request.

Example Fetch Story File

Here's an example of a Fetchbook fetch story file adhering to the TypeScript definition and the naming convention (ending with .fetch.ts):

// examples/venusaur.fetch.ts
import { FetchStory } from "fetchbook";

export default {
  name: "Get info about Venusaur",
  url: "https://pokeapi.co/api/v2/pokemon/venusaur",
  init: {
    method: "GET",
  },
  expect: {
    status: 200,
    headers: {
      "content-type": "application/json; charset=utf-8",
    },
    body: {
      order: 3,
      name: "venusaur",
      height: 20,
      weight: 1000,
    },
  },
} satisfies FetchStory;

Ensure that your story files adhere to this structure, type definition, and the naming convention (.fetch.ts) to work seamlessly with Fetchbook. You can create multiple fetch story files to describe different HTTP requests and use Fetchbook to manage and execute them as needed.

Contributing

Contributions are welcome! These are some of the current pending tasks:

  • Print response body by default to mimic a standard cURL request.
  • Add command to create a story: fetchbook create.
  • Add command to import a story from other formats: fetchbook import.
  • Add a command to start a web ui: fetchbook studio.

License

Fetchbook is licensed under the MIT License. Feel free to use and modify it according to your needs.


Enjoy using Fetchbook for efficient HTTP request management! If you encounter any issues or have suggestions for improvement, please don't hesitate to open an issue or contribute to the project.

More Repositories

1

react-guitar

A beautiful and accessible guitar component for React. βš›οΈ 🎸
TypeScript
618
star
2

next-plausible

Simple integration for https://nextjs.org and https://plausible.io analytics
TypeScript
506
star
3

creepyface

The JavaScript library that makes your face look at the pointer. πŸ€ͺπŸ–±οΈπŸ‘†
TypeScript
486
star
4

rollup-plugin-browsersync

Serve your bundle via Browser Sync
JavaScript
19
star
5

liferay-pokemon-item-selector

Code for Liferay's /dev/24 talk
Java
12
star
6

storybook-tailwind2

Sample setup for Storybook and Tailwind@2
JavaScript
7
star
7

liferay-super-deploy

Deploy all changed modules at once (hopefully).
Shell
6
star
8

liferequest

From http://localhost:8080 to HTML
4
star
9

liferay-devcon-headless-2023

Liferay Devcon 2023 Headless Talk
FreeMarker
4
star
10

uptimerobot-node-client

NodeJS client for the uptimerobot API
JavaScript
3
star
11

elm-music-player

Music player written in Elm at a Haskell Madrid Meetup
Elm
2
star
12

emoji-chat

Emoji chat for WeDeploy Hackathon
JavaScript
2
star
13

npm-card

My NPM card πŸ’³
JavaScript
1
star
14

react-creepyface

React component for https://github.com/4lejandrito/creepyface.
1
star
15

me

My personal site
TypeScript
1
star
16

try_git

1
star
17

liferay-rest-client-for-templates

Example of a template migration from serviceLocator to restClient
FreeMarker
1
star
18

creepyface-firefly

A point provider for Creepyface
1
star
19

c2t-chrome

Car to Trello Chrome Extension
JavaScript
1
star
20

wercker-box-play

Wercker box for play 2.2.x apps
1
star
21

cliferay

Daily scripts to work with Liferay
Shell
1
star
22

liferay-headless-playwright

Playwright first steps for the Headless team
TypeScript
1
star