Skip to content

viktormarinho/fetch-to-curl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@viktor/fetch-to-curl

Generate curl requests with the inputs you would usually use for the JS fetch.

This is a fork of this other project.

The original was written in Javascript, had a manually maintained and outdated types.ts and had a lot of tooling that i saw as overkill so i made a simpler version that fits my needs.

This version uses Deno, but should be compatible with any modern JS runtime since it contains 0 dependencies and is being distributed in JSR.

If you need something that works in old IE browsers, go for the other version.

Thanks to https://github.com/leoek for creating the original one.

Installation

deno add @viktor/fetch-to-curl

or

npx jsr add @viktor/fetch-to-curl

Usage

import { fetchToCurl } from 'jsr:@viktor/fetch-to-curl';

const url = 'https://jsonplaceholder.typicode.com/posts/1';
const options = {
  headers: {
    Authorization: "BASIC SOMEBASE64STRING"
  },
  method: 'get'
};
// Log your request
console.log(fetchToCurl(url, options));
// Do your request
fetch(url, options);

// Output
curl "https://jsonplaceholder.typicode.com/posts/1" -X GET -H "Authorization: BASIC SOMEBASE64STRING"

// fetchToCurl arguments should always match the fetch standard parameters.

About

Convert javascript fetch requests to curl

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 11