Superagent Parsing Typed HTTP Responses

Use Superagent to GET and POST with automatic parsing, retries, timeout control, and typed response body access for JSON and form payloads.

JavascriptData Fetching

Code

snippet
import superagent from 'superagent';

const agent = superagent.agent();

const profile = await agent
  .get('https://api.example.com/profile')
  .set('Authorization', 'Bearer demo-token')
  .query({ fields: 'name,email' })
  .timeout({ response: 4000, deadline: 9000 })
  .retry(2, (err, res) => !!err || res.status >= 500);

console.log('profile name:', profile.body.name);

const created = await agent
  .post('https://api.example.com/orders')
  .type('json')
  .send({ sku: 'A-1', quantity: 3 })
  .on('error', (err) => console.error('submit failed:', err.message));

console.log('created order id:', created.body.id);

const form = await agent
  .post('https://api.example.com/feedback')
  .type('form')
  .send({ rating: 5, comment: 'great' });
console.log('form status:', form.status);