All Collections
Developers
Client library recipes
Client library recipes

This guide collects recipes for using the Geora API using different languages and client libraries.

Geora avatar
Written by Geora
Updated over a week ago

Elm

Geora’s own SaaS platform is built using the Elm language, with the code-generating client side tool elm-graphql. This gives us a type-safe library for building GraphQL queries and mutations against our schema.

A simple example is fetching an actor using this query:

{
actor(id: "YWN0b3J8YXNrZGFzbGRqa2FzZA==") {
id
name
email {
email
}
}
}

In Elm, we define a data type Actor to hold some actor information (its ID, name, and email address). elm-graphql will generate a typed API for constructing queries, which are built using the SelectionSet type. Here, selActor takes an ID and builds a GraphQL query to request the actor information and construct an Actor based on the response.

type Actor = Actor Id String Email

selActor : Id -> SelectionSet Actor RootQuery
selActor id =
Query.actor { id = id }
(SelectionSet.succeed Actor
|> with GeoraAPI.Object.Actor.id
|> with GeoraAPI.Object.Actor.name
|> with
(GeoraAPI.Object.Actor.email
GeoraAPI.Object.EmailInfo.email
|> nonNullOrFail))
|> nonNullOrFail

If the API request is invalid or doesn’t match the schema, Elm will provide a helpful compile-time error. Please see the elm-graphql documentation for more details.


Typescript

You can use a HTTP library like node-fetch:

import fetch, { RequestInit, Response } from "node-fetch";

const ACTOR_QUERY: string = `
query ($id: ID!) {
actor(id: $id) {
id
name
email {
email
}
}
}
`;

async function query(): Promise<Response> {
const url: string = "https://api.geora.io/v2";

const headers: { [header: string]: string } = {
"Content-Type": "application/json",
"Authorization":
`Bearer ${process.env.GEORA_TOKEN}`,
};

const id: string = "YXNzZXRWZXJzaW9ufDI=";

const options: RequestInit = {
method: "POST",
headers,
body: JSON.stringify({
query: ACTOR_QUERY,
variables: { id },
}),
};

return fetch(url, options);
}

async function main(): Promise<JSON> {
const response: Response = await query();
return await response.json();
}

main().then((res: JSON) => console.log(res["data"]));


Python

You can use a HTTP library like requests:

import requests
import os

ACTOR_QUERY = """query ($id: ID!) {
actor(id: $id) {
id
name
email {
email
}
}
}"""

def query():
url = "https://api.geora.io/v2"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {os.environ['GEORA_JWT']}"
}

id = "YXNzZXRWZXJzaW9ufDI="
request = requests.post(
url,
json={
"query": ACTOR_QUERY,
"variables": { "id": id }
},
headers=headers
)
return request.json()

result = query()
print(f"{result['data']}")


Curl

For small queries, curl on the command line is useful. It’s important to set the Content-Type header, and add your authorisation token. The actual query is then passed in using --data-binary:

curl 'https://api.geora.io/v2' \
-H 'Content-Type: application/json' \
-H 'Authorisation: Bearer ...' \
--data-binary '{"query":"{ actor( id: \"YXNznXRWZXJzaW9ufDEyMTgzNwo=\") {id, name, email {email}}}"}' \
--compressed

Need some help? 🤔

Get in touch using the live chat button to the bottom right of any Geora page and you'll be connected to us in real time! 👉

Did this answer your question?