- 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 init
to 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
.Use the client
You can now import the client into your project and start using it.Domain
Indicate the domain you’re using by passing theconfig
object to all client calls and setting requestUrl
to your currently requested URL: