Skip to content

v3 clients, Postman and Bruno

Import the v3 API into Postman or Bruno, or make a typed client in TypeScript, Python or Go from the spec.

Everything on this page is made from the v3 OpenAPI spec, /public/v3/openapi.yaml, by pinned tools. The files are made again on every spec change, and our CI runs each example against the API, so they never drift from it.

In every typed client, each field but the key (id, or code for countries and currencies) is optional, or a pointer in Go. That is on purpose: fields[users]=id,name and the other sparse fieldsets leave the rest out, so a client must not count on them. Without fields, every field is there.

Postman and Bruno

  • Postman collection: in Postman, choose Import and pick the file. Put your token in the collection variable bearerToken.
  • Bruno collection: in Bruno, choose Import Collection, then Bruno Collection. Pick the GoRest environment and put your token in its token variable.

Both send the token on every request, from the one setting. With a token, the reads show your own rows as well as the sample data; without one, the reads still work. Optional parameters are listed but turned off. Make a token on the tokens page.

TypeScript

Types from openapi-typescript 7.13.0 and calls from openapi-fetch 0.17.0. Node 24 runs the .ts file as it is.

npm install openapi-fetch@0.17.0
npm install --save-dev openapi-typescript@7.13.0 typescript@5.9.3
npx openapi-typescript https://gorest.co.in/public/v3/openapi.yaml --default-non-nullable false -o schema.d.ts
import createClient from 'openapi-fetch';
import type { paths } from './schema.d.ts';

const token = process.env.GOREST_TOKEN;
const api = createClient<paths>({
  baseUrl: 'https://gorest.co.in/public/v3',
  headers: token ? { Authorization: `Bearer ${token}` } : {},
});

const { data, response } = await api.GET('/users', { params: { query: { 'page[size]': 2 } } });
if (!data) throw new Error(`list users: status ${response.status}`);
console.log(data.data.map((u) => u.name));

Python

A client package from openapi-python-client 0.29.1, on httpx and attrs.

pip install openapi-python-client==0.29.1
curl -o v3.yaml https://gorest.co.in/public/v3/openapi.yaml
openapi-python-client generate --path v3.yaml --meta none --output-path gorest_v3
import os
from gorest_v3 import AuthenticatedClient
from gorest_v3.api.users import list_users
from gorest_v3.models import UserList

client = AuthenticatedClient(base_url='https://gorest.co.in/public/v3', token=os.environ['GOREST_TOKEN'])
users = list_users.sync_detailed(client=client, pagesize=2)
if not isinstance(users.parsed, UserList):
    raise SystemExit(f'list users: status {users.status_code}')
print([u.name for u in users.parsed.data])

The generator leaves out the four /http/echo request bodies (any content type) and the YAML answer of /openapi.yaml, and says so in a warning. With no token, use Client(base_url=...): it sends no Authorization header, and the reads still work.

Go

Types and a client from oapi-codegen v2.8.1, the tool the GoRest server itself is made with.

# oapi-codegen.yaml
package: gorest
output: gorest/client.gen.go
generate:
  models: true
  client: true
curl -o v3.yaml https://gorest.co.in/public/v3/openapi.yaml
go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@v2.8.1 -config oapi-codegen.yaml v3.yaml
c, _ := gorest.NewClientWithResponses("https://gorest.co.in/public/v3",
	gorest.WithRequestEditorFn(func(_ context.Context, r *http.Request) error {
		if t := os.Getenv("GOREST_TOKEN"); t != "" {
			r.Header.Set("Authorization", "Bearer "+t)
		}
		return nil
	}))
size := 2
users, err := c.ListUsersWithResponse(ctx, &gorest.ListUsersParams{PageSize: &size})
if err != nil || users.JSON200 == nil {
	log.Fatal("list users failed")
}
fmt.Println(len(users.JSON200.Data), "users")
Related guides

Keep going