Skip to main content

Automated Testing and Documentation for your REST API

Project description

ScanAPI

A library for your API that provides:

  • Automated Testing
  • Automated Documentation

How to install

$ pip install scanapi

How to use

Create an API spec file api.yaml file in the root of your project and list the API's endpoints.

api:
  base_url: https://jsonplaceholder.typicode.com/
  endpoints:
    - namespace: posts
      path: /posts
      requests:
        - name: list_all
          method: get
        - name: details
          method: get
          path: /1

To run the requests and create the doc, run:

$ scanapi --help
Usage: scanapi [OPTIONS]

  Automated Testing and Documentation for your REST API.

Options:
  -s, --spec-path PATH
  -d, --docs-path TEXT
  --help                Show this message and exit.

By default, the doc will be available in the docs.md file.

Configuration

If you want to configure scanapi, you can do it by creating a file .scanapi.yaml in the root of your project.

spec_path: api.yaml
docs_path: docs.md

Headers

api:
  base_url: https://jsonplaceholder.typicode.com/
  headers:
    Authorization: Bearer 3032196d-4563-4047-ac7b-e7763e43177e
  endpoints:
    - namespace: posts
      headers:
        Content-Type: application/json
      path: /posts
      requests:
        - name: list_all
          method: get
        - name: details
          method: get
          path: /1

Cases

To be implemented

Environment Variables

You can use environment variables in your API spec file:

api:
  base_url: ${BASE_URL}
  headers:
    Authorization: ${BEARER_TOKEN}
  endpoints:
    - namespace: posts
      headers:
        Content-Type: application/json
      path: /posts
      requests:
        - name: list_all
          method: get
        - name: details
          method: get
          path: /1

And in the config file .scanapi.yaml set their values:

env-vars:
  BASE_URL: https://jsonplaceholder.typicode.com/
  BEARER_TOKEN: Bearer 3032196d-4563-4047-ac7b-e7763e43177e

Chaining Requests

api:
  base_url: ${BASE_URL}
  headers:
    Authorization: ${BEARER_TOKEN}
  endpoints:
    - namespace: posts
      headers:
        Content-Type: application/json
      path: /posts
      requests:
        - name: list_all # posts_list_all
          method: get
          vars:
            post_id: ${{responses['posts_list_all'].json()[1]['id']}} # should return id 2
        - name: details # posts_details
          method: get
          path: ${post_id}

Nested Endpoints

Split API spec file in multiples files

To be implemented:

- api/
  - api.yaml
  - endpoints/
    - endpoints.yaml
    - posts/
      - posts.yaml
      - requests/
        - list-all.yaml
        - details.yaml

Asserts

To be implemented

Automation with Peril

To be implemented

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scanapi-0.0.8.tar.gz (4.5 kB view hashes)

Uploaded Source

Built Distribution

scanapi-0.0.8-py3-none-any.whl (6.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page