Skip to content

Quick Start

This guide walks you through creating and running your first HTTP request with @t-req/core.

Create a file called api/users.http:

### Get Users
GET https://jsonplaceholder.typicode.com/users
Accept: application/json
import { createClient } from '@t-req/core';
import { createNodeIO } from '@t-req/core/runtime';
const client = createClient({
// Required in Node to run from files
io: createNodeIO(),
});
const response = await client.run('./api/users.http');
const users = await response.json();
console.log(`Found ${users.length} users`);

In Bun, the IO adapter is optional—@t-req/core uses Bun’s built-in filesystem APIs:

import { createClient } from '@t-req/core';
const client = createClient();
const response = await client.run('./api/users.http');
const users = await response.json();
console.log(`Found ${users.length} users`);

Create a .http file with variables:

### Get User by ID
GET https://jsonplaceholder.typicode.com/users/{{userId}}
Accept: application/json

Pass variables when running:

const response = await client.run('./api/user.http', {
variables: { userId: '1' },
});
const user = await response.json();
console.log(`User: ${user.name}`);

For desktop apps or when you don’t have filesystem access, use runString():

import { createClient } from '@t-req/core';
const client = createClient();
const httpContent = `
GET https://jsonplaceholder.typicode.com/users/{{userId}}
Accept: application/json
`;
const response = await client.runString(httpContent, {
variables: { userId: '1' },
});
const user = await response.json();
console.log(`User: ${user.name}`);