Connecting to API

8base provisions all database tables with over one-dozen built-in GraphQL schemas. These resources allow you to perform any Create, Read, Update and Delete (CRUD) action needed to effectively manage your data. Additionally, it doesn't matter what technology you're using for a client - or server - application. As long as you can perform web requests, you'll be able to connect to your 8base workspace endpoints.

Setup

In the following examples, we've made a few assumptions (feel free to re-create them for your learnings sake!). Those assumptions are the following:

  1. You manage a workspace named Todo's Workspace

  2. You've defined a table named Todos

  3. The Todos table has the following fields:

    • text: text

    • completed: switch, { format: Yes/No }

  4. One or more Todos records have been created

  5. Guest users are permitted CRUD access on the Todos table

  6. An API token has been created for a role named Developer.

Executing API Calls

In all of the following examples, make sure to replace all occurances of {API_ENDPOINT} with your workspace's endpoint and all occurances of {API_TOKEN} with your developer API token.

Example GraphQL Query

Bash
JavaScript
Python
curl -X POST {API_ENDPOINT} \
-H "Content-Type: application/json" \
-d '{ "query": "{ todosList { items { text } } }" }'

Example GraphQL Mutation

Bash
JavaScript
Python
curl -X POST {API_ENDPOINT} \
-H "Content-Type: application/json" \
-d '{ "query": "mutation TodoCreate { todoCreate(data: {text: \"from CURL\", completed: false}) {id text completed}}"}'

Example GraphQL Mutation with Authentication

Bash
JavaScript
Python
curl -X POST {API_ENDPOINT}\
-H "Content-Type: application/json" \
-H 'Authorization: Bearer {API_TOKEN}' \
-d '{ "query": "mutation TodoCreate { todoCreate(data: {text: \"from CURL with auth\", completed: false}) {id text completed}} "}'