30 RequestData - HeinrichConvidera/RESTful-API-Gateway-Wiki GitHub Wiki

Request Data

This chapter will show you how to request data from the RESTful API Gateway.

Table of Contents

  1. Get data via REST API
  2. Get data via GraphQL

Get data via REST API

By default all avalible data will be responded. If you want to limit the response to just a few fields you could pass the fields via the query operator.

# field limitation examples
-d 'fields=id|username|comments.id|comments.content'
-d 'fields=id|username|comments'
-d 'fields=id|username|comments.*'
-d 'fields=*'

# or
"<url>?fields=..."

Examples

# get all users
curl "http://localhost/users?api_token=<api-token>"

# get all users only the id
curl "http://localhost/users?api_token=<api-token>&fields=id"

# get user with id
curl "http://localhost/users/b6665598-c35c-4b70-bbdb-dc4e14f1a6e9?api_token=<api-token>"

# get user comments
curl "http://localhost/users/b6665598-c35c-4b70-bbdb-dc4e14f1a6e9/comments?api_token=<api-token>"

# get user comment with id
curl "http://localhost/users/b6665598-c35c-4b70-bbdb-dc4e14f1a6e9/comments/0a8b39e3-4bcb-442d-8543-94bd2d46a381?api_token=<api-token>"

Get data via GraphQL

For GraphQL support you need to add Content-Type: application/graphql to the headers.

To request data via GraphQL there are two posibile ways. Send your GraphQL Query directly or in JSON encapsulated.

# Request via GraphQL Query
{
    users {
        id,
        comments {
            id,
            content
        },
        username
    }
}

# Request via JSON
{ "query": "{users{id,comments{id,content},username}}" }

Examples

The following examples will be sent directly as GraphQL Queries.

# get all users
data='{
    users {
        id,
        comments {
            id,
            content
        },
        username
    }
}'
curl -d "$data" -H "Content-Type: application/graphql" -X POST "http://localhost?api_token=<api-token>"

# get user with id
data='{
    user (id: "b6665598-c35c-4b70-bbdb-dc4e14f1a6e9") {
        id,
        comments {
            id,
            content
        },
        username
    }
}'
curl -d "$data" -H "Content-Type: application/graphql" -X POST "http://localhost?api_token=<api-token>"

# get user comments
data='{
    comments {
        id,
        content
    }
}'
curl -d "$data" -H "Content-Type: application/graphql" -X POST "http://localhost/users/b6665598-c35c-4b70-bbdb-dc4e14f1a6e9?api_token=<api-token>"

# get user comment with id
data='{
    comment (id: "0a8b39e3-4bcb-442d-8543-94bd2d46a381") {
        id,
        content
    }
}'
curl -d "$data" -H "Content-Type: application/graphql" -X POST "http://localhost/users/b6665598-c35c-4b70-bbdb-dc4e14f1a6e9?api_token=<api-token>"
⚠️ **GitHub.com Fallback** ⚠️