Skip to content

iatsiuk/undici-for-dummies

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

GET

const { body } = await request('http://localhost:1380/get', {
  headers: { 'User-Agent': 'undici' },
  query: { foo: 'bar' },
});

console.log('data', await body.json());

POST

const { body } = await request('http://localhost:1380/post', {
  method: 'POST',
  headers: {
    'content-type': 'application/json',
  },
  body: JSON.stringify({ foo: 'bar' }),
});

console.log('data', await body.json());

POST form

import { URLSearchParams } from 'url';

const formData = new URLSearchParams();

formData.append('foo', 'bar');

const { body } = await request('http://localhost:1380/post', {
  method: 'POST',
  headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
  body: formData.toString(),
});

console.log('data', await body.json());

About

Pino for dummies

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published