- Types for all API responses and payloads
- Autocompletion and type checking for queries and parameters
- Dynamic resolving of API endpoints
- Authentication and header management
- Convenience methods for tracking API usage and monitoring performance
- Token management for releases
See how it works
See how it works
1
API Schema
Frontstack generates a schema for your API, based on the blocks and pages that you have defined.
openapi.yml
The cool part - this schema is a fully compliant OpenAPI 3.1.0 specification, so you can use it with any OpenAPI tooling - for example import it into Postman or generate server stubs in other languages.
2
Translate into TypeScript definitions
The schema is then transformed into a set of TypeScript interfaces and types that define your API.
.frontstack/generated-types.d.ts
3
Generate client module
A client module is generated that provides convenient, typesafe and annotated methods for interacting with the API.
.frontstack/generated-client.js
4
Use the client
You can now use the client library in your frontend project
index.ts
Prerequisites
In order to complete this guide, you will need:- Node.js installed on your machine
- An existing Node.js project (or run
pnpm initto create one), ideally with TypeScript - A Frontstack account
- The Frontstack CLI installed globally or using
npx - We recommend that you use pnpm as your package manager
Login and connect project
Before we proceed, we need to open our current project directory in the terminal. It is wherever you have yourpackage.json file.
A browser window will open, and you will be prompted to login to your Frontstack account.
info command:
project command:
.frontstack-local directory that contains your project configuration.
We recommend that you add this directory to your .gitignore file, because it contains sensitive information, such as your Frontstack API token.
.gitignore
Generate client
Now that you have connected your project, you can generate the client..frontstack directory in your project root:
generated-client.js- The client that you can import into your projectfetch-api.d.t- Type definitions for the clientgenerated-types.d.ts- Type definitions for the schemaquery-types.ts- Type definitions for queries
Troubleshooting
Troubleshooting
In case you get an error, you can try to delete the
.frontstack-local directory and run the login and project commands again.If you are using the frontstack command, make sure that it is installed globally and updated to the latest version (run pnpm add -g @frontstackdev/cli).Check that you are using the latest version using frontstack --version or npx @frontstackdev/cli --version.When using npx, you can always use the @latest tag to ensure that you are using the latest version of the CLI.Use the client
You can now import the client into your project and start using it. There are two ways to use the generated client:Option 1: Direct client import (simple projects)
For simple use cases without global configuration:Option 2: Factory function with configuration (recommended)
For projects that need global configuration (e.g., proxy URL for CORS prevention):Domain
Indicate the domain you’re using by passing theconfig object to all client calls and setting requestUrl to your currently requested URL:
Proxy URL (CORS prevention)
If you’re making requests from a browser and experiencing CORS issues, you can configure a proxy URL either globally or per-request. The client will concatenate the proxy URL with the original API path. For example, if the original request would go tohttps://api.frontstack.com/block and you set proxyUrl: '/api', the request will be sent to /api/block on your current domain.
Global configuration (recommended):
fs-target-url header.