59

GitHub - kiranz/just-api: Specification based API test framework for HTTP APIs (...

 5 years ago
source link: https://github.com/kiranz/just-api
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.md

Just-API

npm package

Join the chat at https://gitter.im/just-api/Lobby

Just-API is a robust, specification based, codeless testing framework that tests REST, GraphQL (or any HTTP based) APIs. It runs on node.js. Just-API allows users to test APIs without writing code. It takes API test specification from YAML files and runs them either in serial mode or in parallel mode as instructed by the user. It also reports errors and test results in several formats including HTML and JSON.

In simple terms, how it works is that you provide request and response validation specification in an yaml file. Just-API builds the request, makes a call to server and validates response as per the specification. You can choose to validate any or all of response status code, headers, JSON data, JSON schema or provide your own custom validator function.

Find more about it here

Links

Getting Started

Following is a simple example showing usage of Just-API.

To run just-api, you will need Node.js v7.10.0 or newer.

$ npm install just-api
$ mkdir specs
$ $EDITOR specs/starwars_service.yml # or open with your preferred editor

In your editor (make sure yaml is properly indented)

meta:
  name: Star Wars suite
configuration:
  scheme: https
  host: swapi.co
  base_path: /api
specs:
  - name: get "Luke Skywalker" info
    request:
      path: /people/1/
      method: get
    response:
      status_code: 200
      json_data:
        - path: $.name
          value: Luke Skywalker

Back in the terminal

$ ./node_modules/.bin/just-api

   ✓ get Luke Skywalker info (1516ms)

  Done: specs/suite.yml (Passed)

0 skipped, 0 failed, 1 passed (1 tests)
0 skipped, 0 failed, 1 passed (1 suites)
Duration: 1.6s

Testing GraphQL APIs

Following example tests a GraphQL API that returns location for a given ip address.

Create the yaml suite file and run just-api.

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

You can do much more advanced stuff with Just-API. Our documentation says it all. Take a look at Just-API Website for detailed documentation.

License

MIT


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK