API Access
Now we've successfully deployed our GraphQL API, it's time to consume the API outside our local and Grafbase environments.
From the Dashboard you will want to click Connect. Here you can copy the API endpoint you will use to send requests to.
You can alternatively switch to another branch to get a different API endpoint.
Grafbase protects access and provides multiple methods to access it. We'll be using API Keys in this quickstart, but you could also use JWTs for authenticated users.
From your API keys list, copy the Production key.
Now use the endpoint and API key obtained above to make a GraphQL request. We'll be using the hosted HTTPie to throughout the rest of this tutorial.
Make sure set the request method to POST
and add your endpoint.
You will then want to pass the API Key as a header with the key x-api-key
.
Now all that's left to do before we make a request and set GraphQL
as the content type.
Finally it's time to make a request! Let's create our first Post
entry in our production database!
In the response to our GraphQL request we'll fetch the id
, title
, url
, and two system fields that are automatically managed by Grafbase — createdAt
and updatedAt
.
mutation CreateNewPost($title: String!, $url: String!) {
postCreate(input: { title: $title, url: $url }) {
post {
id
title
url
createdAt
updatedAt
}
}
}
That's it! You just created your first GraphQL API and deployed it to the edge with Grafbase!
There's more to learn as you grow your backend — learn more