APIs
Your Keel backend exposes three types of APIs:
- GraphQL
- JSON, and
- JSON-RPC
When running Keel locally using keel run
you can make requests to your API at http://localhost:8000/api/${apiType}
and for deployed environments you'll find the domain on the Overview page in the Keel console.
Code generation
We recommend using the Keel CLI to generate client code for your API. The CLI will generate a fully-typed TypeScript client for your API with autocompletion and type hints. It is the preferred way to interact with your Keel backend and recommended over directly calling the API endpoints.
To learn more about the generated client, visit its documentation page.
GraphQL API
Endpoint: /api/graphql
GraphQL (opens in a new tab) is an open-source data query language that allows clients to specify the data they need from the API. It also allows querying data across relational data models, meaning that you can do in one API call what might otherwise require several.
When running locally with keel run
you can also access a GraphiQL (opens in a new tab) playground at /api/graphiql
.
JSON API (OpenAPI)
Endpoint: /api/json/<actionName>
OpenAPI (opens in a new tab) is an open-source specification for describing JSON APIs. It describes which endpoints are available and the data-type's of the requests and responses. There are many open source libraries for generating clients from an OpenAPI spec and you can download the OpenAPI (v3.1) definitions for your JSON API from the API Explorer in the Keel console or from the /api/json/openapi.json
endpoint of your Keel app.
JSON-RPC API
Endpoint: /api/rpc
JSON-RPC (opens in a new tab) is a lightweight Remote Procedure Call (opens in a new tab) (RPC) protocol. The JSON-RPC endpoint is /api/rpc
and is compliant with the JSON-RPC 2.0 spec.
Which API should I use?
We support these different types of endpoints to give you flexibility in how to connect to your Keel app. If you are building a web frontend and have used GraphQL before or want to be able to load lots of relational data in one request, then GraphQL may be a good choice.
If you want a simpler option with a more standard request/response pattern then the JSON API might be more for you.
In the future you'll be able to generate a fully-typed client for your API using the Keel CLI.
Authentication
All APIs use the same JWT (opens in a new tab) (JSON Web Token)-based authentication. First you need to get an access token by authenticating. You can then pass this access token in the Authorization
header on all subsequent requests.
Authorization: Bearer <access token>
See the individual API docs for examples.