import { get } from 'request'; get('https://example.com/api/data', (error, response, body) => { if (error) { console.error(error); } else { console.log(body); } });
import { post } from 'request'; const data = { name: 'John', age: 30, }; post('https://example.com/api/user', { json: data }, (error, response, body) => { if (error) { console.error(error); } else { console.log(body); } });
import { put } from 'request'; const data = { name: 'John', age: 30, }; const headers = { 'Content-Type': 'application/json', 'Authorization': 'BearerIn this example, we import the `put` function from the `request` library and use it to make a PUT request to `https://example.com/api/user/123`, with a payload of JSON data containing a name and age field, and headers with a Content-Type of `application/json` and an Authorization token. When the response comes back, we log the body of the response to the console. Package library: `request`', }; put('https://example.com/api/user/123', { json: data, headers }, (error, response, body) => { if (error) { console.error(error); } else { console.log(body); } });