fetch-aws4
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

Fetch AWS V4

Wapper around node-fetch libray to sign the request with AWS V4 signature headers

Setup

import fetch from 'fetch-aws4';
import nodeFetch from 'node-fetch';
import { wrapper } from 'fetch-aws4';

void (async () => {
    // Getting credentials from environment var: AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
    const response = await fetch('https://httpbin.org/html');
    console.log(await response.text());

    // Passing credentials as options
    const response = await fetch('https://httpbin.org/html', {
        credentials: {
            accessKeyId: 'key',
            secretAccessKey: 'secret',
            sessionToken: 'optional token',
        }
    });
    console.log(await response.text());
})();

Working with JSON

const jsonResponse = await fetch('https://httpbin.org/json');
console.log(await jsonResponse.json());

POST request

const postResponse = await fetch('https://httpbin.org/post', {
    method: 'POST',
});
console.log(await postResponse.json());

Custom wrapper

const nodeFetchResponse = await wrapper(nodeFetch)('https://httpbin.org/get');
console.log(await nodeFetchResponse.json());

Readme

Keywords

Package Sidebar

Install

npm i fetch-aws4

Weekly Downloads

2,019

Version

1.0.3

License

LGPL-3.0-or-later

Unpacked Size

13 kB

Total Files

9

Last publish

Collaborators

  • abdala