Skip to main content

A simple REST API client CLI utility

Project description

Api Rester

A lightweight command-line REST client for testing APIs without the overhead of GUI applications like Postman or Insomnia.

Installation

Api Rester can be installed through pip package manager with the following command

pip install api-rester

Features

  • API Calls execution with request and response stored on JSON files
  • Support for all major HTTP methods (GET, POST, PUT, DELETE, HEAD, PATCH)
  • Query parameters support
  • Environment variables replacement on request and response files
  • Alternative request and response files
  • Verbose logging mode for debugging

Coming in the future

  • Network error handling
  • Environment variables from file
  • Persistent cookies support

Basic Usage

  1. Create a request file, by default the application recognizes the file as request.json
{
    "protocol": "https", // required (http or https)
    "host": "api.example.com", // required
    "path": "/api/v1/users", // required
    "method": "POST", // required (GET, POST, PUT, DELETE, HEAD, PATCH)
    "headers": {
        "Content-Type": "application/json"
    },
    "body": {
        "name": "John Doe",
        "email": "john.doe@example.com"
    }
}
  1. Execute the request
api-rester call
  1. The application will execute the request and save the response in the response.json file
{
    "status": 200,
    "headers": {
        "Content-Type": "application/json"
    },
    "body": {
        "id": 59,
        "name": "John Doe",
        "email": "john.doe@example.com" 
    }
}

Custom Files

The application supports alternative files to be used as a request and response.

For example, if you have a file called example-file.json and want to receive the response in a different file called example-response.json, you can use it as a request by running the following command:

api-rester call --request-file example-file.json --response-file example-response.json

The application will execute the request and save the response in the example-response.json file.

Environment Variables

The application supports environment variables to be replaced in the request.json file.

For example, if you have an environment variable called API_KEY, you can replace it in the request.json file with ${{API_KEY}}.

{
    // ...
    "path": "/api/v1/users/${{API_KEY}}"
    // ...
}

When you execute the request, the application will replace the ${{API_KEY}} with the value of the API_KEY environment variable.

API_KEY="1234567890" api-rester call

The application will replace the ${{API_KEY}} with the value of the API_KEY environment variable and execute the request.

{
    // ...
    "path": "/api/v1/users/1234567890"
    // ...
}

Example

  1. Create a request file called example-file.json
{
    "protocol": "https",
    "host": "api.example.com",
    "path": "/api/v1/users",
    "method": "POST",
    "headers": {
        "Content-Type": "application/json",
        "Authorization": "Bearer ${{API_KEY}}"
    },
    "body": {
        "name": "John Doe",
        "email": "john.doe@example.com"
    }
}
  1. Execute the request
API_KEY=1234567890 api-rester call --request-file example-file.json --response-file example-response.json
  1. The application will execute the request and save the response in the example-response.json file
{
    "status": 200,
    "headers": {
        "Content-Type": "application/json"
    },
    "body": {
        "id": 59,
        "name": "John Doe",
        "email": "john.doe@example.com"
    }
}

Template generation

Api rester can also generate a template of what it expects as a request with this command:

api-rester template

Which you can specify the path with --filename or --f

api-rester template --filename custom_place.json

It will generate this file:

{
  "protocol": "http",
  "host": "localhost:3000",
  "path": "/",
  "method": "GET",
  "headers": {
    "Content-Type": "application/json"
  },
  "body": {
    "message": "Hello world"
  }
}

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

api_rester-0.2.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

api_rester-0.2.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file api_rester-0.2.0.tar.gz.

File metadata

  • Download URL: api_rester-0.2.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for api_rester-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b463942b1be7a0df4e6fd64e5b2743a56fd40521d15575777a029c42176ce7ca
MD5 c9b1528ef91beeef24e7b6e5a2ead61a
BLAKE2b-256 7716605527091f266180b2a4cad5213de3fcbf11838c19591d0addf5dc6ca03c

See more details on using hashes here.

File details

Details for the file api_rester-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: api_rester-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for api_rester-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 48729ac4fcd2cbd4bb3c841b95b97fa5898fce575c3a175e4ce8d6f7af4e8bab
MD5 3a496a19e44565e44c2ea9754952451c
BLAKE2b-256 7b66d936a6cce4e567744fc4a762b1a771bace3e864153a8a48b2de775544c85

See more details on using hashes here.

Supported by

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