Giter Club home page Giter Club logo

api-simulator's Introduction

API Simulator

Simulate API requests based on sample api data.

1. Basic Usage

This sample JSON file payload-sample.json demonstrates how to structure requests for different HTTP methods, including GET and POST, with placeholders in the URL path that will be replaced with fake data by the script. The headers and body fields are optional and can be used to customize the request headers and body content.

  • Create a Virtual Environment and Install python dependencies
python3 -m venv env
source env/bin/activate
pip install -r requirements.txt
  • Run simulator with sample payloads.
python3 simulator.py --file payload-sample.json --global_domain https://api.example.com

Arguments

This script accepts several command-line arguments to customize its behavior. Here's a breakdown of each argument:

  • --file: Specifies the file containing URLs in JSON format. This file should list the URLs to which requests will be sent. The default value is not set, meaning this argument is required.

  • --global_domain: Defines the global domain to prepend to URLs that do not include a domain. This is useful for specifying a base URL for relative paths. The default value is not set. This argument is required if JSON file does not have full domain in the url field.

  • --requests_per_minute: Sets the number of requests per minute. This controls the rate at which requests are sent. The default value is 60.

  • --duration_minutes: Specifies the duration in minutes for which the script will send requests. The default value is 2 minutes.

  • --concurrency: Determines the number of concurrent requests to be made. This can help in managing the load on the server and improving the efficiency of the script. The default value is 1.

1. Changing the Requests Per Minute

To change the number of requests per minute, use the --requests_per_minute argument.

python3 simulator.py --file payload-sample.json --requests_per_minute 20 --global_domain https://api.example.com

2. Changing the Duration in Minutes

To change the duration for which the script will send requests, use the --duration_minutes argument.

python3 simulator.py --file payload-sample.json --duration_minutes 10 --global_domain https://api.example.com

3. Specifying a Global Domain

To specify a global domain that will be prepended to URLs without a domain, use the --global_domain argument.

python3 simulator.py --file payload-sample.json --global_domain https://api.example.com

4. Changing the Concurrency Level

To change the number of concurrent requests, use the --concurrency argument.

python3 simulator.py --file payload-sample.json --concurrency 20 --global_domain https://api.example.com

5. Combining Multiple Arguments

You can combine multiple arguments to customize the script's behavior according to your needs.

python3 simulator.py --file payload-sample.json --requests_per_minute 30 --duration_minutes 10 --global_domain https://api.example.com --concurrency 20

api-simulator's People

Stargazers

Antony Raja. A avatar

Watchers

Fizer Khan (பைசர் கான்) avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.