Use Postman to generate your code for GraphQL API calls

Here is how you can use Postman to help you develop your GraphQL API calls, which provides certain benefits:

  • Faster development of your application, so there are no headaches on how to code your POST requests, since everything is generated.

  • The username and password are already converted to a base64 encoded string, so there’s no need to store the username and password in a configuration file. Instead, you just store the the converted string, which provides extra security.

This example uses the POST method instead of GET to add an extra layer of security for the call.

  1. Install Postman.

  2. Open Postman and create a new request:

    1. Set the method to POST.

    2. Enter the URL that points to the GraphQL service endpoint:

  3. On the Authorization tab, set TYPE to Basic Auth and then enter the authorized user’s username and password.

  4. On the Body tab, select GraphQL and enter your query:

  5. Click the Send button to test your query. If it’s successful, you should see the 200 OK status and the returned JSON result at the bottom of the page.

  6. Generate the code by clicking on the Code link and choosing your preferred programming language (Java - Unirest in this example).

1 Like