
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
ts-fastify-client
Advanced tools
ts-fastify-client <img src="https://readme-typing-svg.demolab.com?font=Fira+Code&size=18&duration=2000&pause=2000¢er=true&width=540&height=80&lines=First+class+api+client+fo
Table of Contents:
To get started, install ts-fastify-client using npm or yarn:
npm install ts-fastify-client
# or
yarn add ts-fastify-client
import { loadRouteDefinitions, createRouteDefinition, z } from 'ts-fastify-client';
const definitions = {
getUser: createRouteDefinition({
method: 'GET',
// Id parameter is dynamicaly injected in the final url.
url: `/user/:id`,
schema: {
params: z.object({
id: z.string(),
}),
response: {
200: z.array(
z.object({
name: z.string(),
age: z.number(),
})
),
},
},
}),
};
const [createClient, schemas] = loadRouteDefinitions(definitions);
// fastify
server.get('/user', { schema: schemas.getUser }, async (request, response) => {
response.status(200).send([{ name: 'John', age: 30 }]);
});
// client
const apiClient = createClient(axios.create({ baseURL: 'localhost' }));
async () => {
const user = await apiClient.getUser({ params: { id: 'my-user-id' } }).call();
// { name: 'John', age: 30 }
};
ts-fastify-client use the /my-url/:my-param syntax to inject given parameters in the final url.
Sometime, instead of calling the client method you will want to get the computed url. It's usefull to use it as a link href for instance.
const url = await apiClient.getUser({ params: { id: 'my-user-id' } }).url;
// https://localhost/user/my-user-id
import { loadRouteDefinitions, createRouteDefinition, Type } from 'ts-fastify-client';
const definitions = {
getUser: createRouteDefinition({
method: 'GET',
// Id parameter is dynamicaly injected in the final url.
url: `/user/:id`,
schema: {
params: Type.Object({
id: Type.String(),
}),
response: {
200: Type.Array(
Type.Object({
name: Type.String(),
age: Type.Number(),
})
),
},
},
}),
};
const [createClient, schemas] = loadRouteDefinitions(definitions);
// fastify
server.get('/user', { schema: schemas.getUser }, async (request, response) => {
response.status(200).send([{ name: 'John', age: 30 }]);
});
// client
const apiClient = createClient(axios.create({ baseURL: 'localhost' }));
async () => {
const user = await apiClient.getUser({ params: { id: 'my-user-id' } }).call();
// { name: 'John', age: 30 }
};
ts-fastify-client use the /my-url/:my-param syntax to inject given parameters in the final url.
Sometime, instead of calling the client method you will want to get the computed url. It's usefull to use it as a link href for instance.
const url = await apiClient.getUser({ params: { id: 'my-user-id' } }).url;
// https://localhost/user/my-user-id
That's it! You can now use ts-fastify-client to create fully typed and safe api client.
FAQs
ts-fastify-client <img src="https://readme-typing-svg.demolab.com?font=Fira+Code&size=18&duration=2000&pause=2000¢er=true&width=540&height=80&lines=First+class+api+client+fo
We found that ts-fastify-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.