fetch-template-literal

1.1.1 • Public • Published

fetch-template-literal

A tool for making http requests using template literals and fetch. It is heavily influenced by http-template-literal but focuses on fetch exlusively.

Installation

npm install --save fetch-template-literal

Browser Usage (with bundler)

const ftl = require('fetch-template-literal')

const result = await ftl`
  POST https://httpbin.org/post/
  Content-Type: application/json

  {"example": true}`

// result is a fetch Response and exposes the expected fields (like .json(), .status, etc)
const json = await result.json()

Node.js Usage

node.js doesn't support fetch by default, so fetch-template-literal can be used as a factory function into which you pass the implementation of fetch you want to use. The example below uses node-fetch.

const fetch = require('node-fetch') 
const ftl = require('fetch-template-literal')(fetch)

const result = await ftl`
  POST https://httpbin.org/post/
  Content-Type: application/json

  {"example": true}`

// result is a fetch Response and exposes the expected fields (like .json(), .status, etc)
const json = await result.json()

Dependents (0)

Package Sidebar

Install

npm i fetch-template-literal

Weekly Downloads

2

Version

1.1.1

License

ISC

Unpacked Size

28.9 kB

Total Files

9

Last publish

Collaborators

  • allain