GraphQL Java Client

Once you have tested your requests with the Altair add-on for instance, you can write a Java program to query a GraphQL server.

Entities in GraphQL are not identified by URLs (in contrast with REST where each resource gets an URL). Instead, a GraphQL server operates on a single URL/endpoint and all GraphQL requests for a given service should be directed at this endpoint.

GraphQL HTTP servers should handle the HTTP GET and POST methods:

This request could be sent via an HTTP GET like so:

(Note: more complex queries are possible, see the documentation for more information)


To send the same query we sent with the Altair GraphQL Client, we can use the following code.

Note that since our query contains special characters (double quotes " around FR), we use an encoder.


See the whole code and an example using a POST method on the Git repo.