Testing REST and GraphQL Services With Just-API

DZone 's Guide to

Testing REST and GraphQL Services With Just-API

Learn how to use Just-API, a specification-based framework for testing REST and GraphQL APIs, to create test suites for services.

· DevOps Zone ·
Free Resource

Just-API is an open-source test framework for APIs. There are several tools and companies available that offer nice UI to test APIs, but none of them really handle complex API automation flows. Often, people go back to programming to test complex flows. Just-API solves these problems by allowing users to test complex API flows with minimal coding, parallel execution, and built-in response validation constructs with nice reporting.

What Is Just-API?

Just-API is a robust, specification-based framework to test REST and GraphQL (or any HTTP-based) APIs. It takes API suite specification from YAML files and runs them either in serial mode or in parallel mode as instructed by the user.

What’s Special About Just-API?

It’s declarative, and allows the user to test APIs with no code. But you can always tap into code when you need to.

How Does It Work?

In simple terms, users build suites by providing request and response validation specification in a YAML suite. Just-API builds the request, makes a call to the ,server and validates response as per the specification. You can choose to validate any or all of

  • Response Status code
  • Response Headers
  • Response JSON body
  • Response JSON schema

or provide your own custom JavaScript validator function.

A Sample REST API Test Suite

This suite tests the people/1 endpoint of a Star Wars service which returns Luke Skywalker details.

  name: Star Wars suite
  scheme: https
  host: swapi.co
  base_path: /api
  - name: get "Luke Skywalker" info
      path: /people/1/
      method: get
      status_code: 200
        - name: content-type
          value: !!js/regexp application/json     
        - path: $.name
          value: Luke Skywalker

As you can see above, It’s quite simple to write tests.

Here we are checking Response.

  • Status code is 200
  • Header value of content-type header matches with Regular expression pattern application/json
  • JSON body object’s name field’s value isLuke Skywalker

A Sample GraphQL Test Suite

The following example tests a GraphQL API that returns the location for a given IP address.

  name: GraphQL location service
  host: api.graphloc.com
  scheme: https
  - name: Get Location of a an ip address
      method: post
      path: /graphql
        - name: content-type
          value: application/json
          type: json
            query: >
                    getLocation(ip: "") {
                      country {
            variables: null
            operationName: null
      status_code: 200
        - path: $.data.getLocation.country.iso_code
          value: US

Sample suite snippets you see here show just the basic stuff we can do with Just-API. It’s packed with tons of useful features.


  • Runs test suites in parallel/serial mode
  • Supports all widely used HTTP methods
  • Supports Form, Multipart requests, File uploads
  • Response Validation (Headers, Status code, JSON body, JSON schema, Custom Response Validation function)
  • Runs imported custom functions from modules
  • Custom inline and module Javascript sync/async functions
  • Hooks (Before all, After all, Before each, After each, Before test, After test)
  • Custom suite configuration
  • Chained Request flows
  • Ability to define/override Request path, query params, path params, headers, body at runtime
  • Storing suite & test data in context for reuse
  • Importing specs from multiple suites
  • Intrasuite and Intersuite spec dependency execution
  • Reusing test specification
  • Retry failed tests
  • Looping: Generate ’n’ number of tests with a list
  • Built-in HTML, JSON reporters
  • Ability to generate reports in multiple formats for the same run
  • Logging HTTP request/response data for failed tests
  • Proper error reporting
  • Runs only tests matching with a given pattern/string
  • Skipping tests with specification
  • Disable or Enable redirections
  • Reports test duration
  • Allows user to plug-in custom reporters

Check it out and feel free to leave feedback, request enhancements, or file issues.


devops ,rest ,graphql ,qa ,api ,test automation ,web services ,automated testing ,tutorial ,open source

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}