Categorygithub.com/mayckol/rest-client
module
1.0.0
Repository: https://github.com/mayckol/rest-client.git
Documentation: pkg.go.dev

# README

Rest Client Logo

Rest Client

Description

RestClient is a simple load testing tool built with Go. It allows you to test the performance of your HTTP services by sending multiple requests concurrently.

This is a simple load testing tool built with Go. It allows you to test the performance of your HTTP services by sending multiple requests concurrently.

Features

  • GET Requests: By default, the tool sends GET requests to the specified URL.
  • POST Requests: You can now send POST requests with a JSON body.
  • Concurrency: Control the number of simultaneous requests.
  • Random ID Generation: Automatically generate or replace an id field in your JSON body for POST requests.

Usage

Build the Docker Image

Before running the rest client, you need to build the Docker image:

docker build -t restclient:latest .

Run the Load Client

Using a .env File To run a load test using a .env file for configuration:

docker run --rm \
  -v /path/to/your/jsonfiles/rest-client:/app/jsonfiles \
  -v /path/to/your/env/rest-client/.env:/app/.env \
  restclient:latest \
  --envpath=/app/.env

GET Requests
To run a simple load test with GET requests:
(Using flags)

docker run --rm restclient \
  --url=http://example.com/ \
  --requests=10 \
  --concurrency=10

POST Requests
To run a load test with POST requests, specify the path to the JSON file that will be used as the body:

docker run --rm \
  -v /path/to/your/jsonfiles:/app/jsonfiles \
  restclient \
  --url=http://example.com/ \
  --requests=10 \
  --concurrency=10 \
  --verb=POST \
  --jsonpath=/app/jsonfiles/body.json

You can also add or replace an id field in the JSON body:

docker run --rm \
  -v /path/to/your/jsonfiles:/app/jsonfiles \
  restclient:latest \
  --url=http://example.com/ \
  --requests=10 \
  --concurrency=10 \
  --verb=POST \
  --jsonpath=/app/jsonfiles/body.json \
  --rand-id-type=number \
  --rand-id-chrs=10

Running on localhost

If you are testing a service running on your localhost, the Docker container's localhost is not the same as your host machine's localhost. To connect to a service running on your host machine, you should use host.docker.internal as the URL.

Example for localhost:

docker run --rm \
  -v /path/to/your/jsonfiles:/app/jsonfiles \
  restclient:latest \
  --url=http://host.docker.internal:8081 \
  --requests=10 \
  --concurrency=10 \
  --verb=POST \
  --jsonpath=/app/jsonfiles/body.json \
  --rand-id-type=number \
  --rand-id-chrs=10

Command Line Options

  • --envpath Path to the .env file.
  • --url The URL of the service to be tested.
  • --requests Total number of requests to send (default: 100).
  • --concurrency Number of simultaneous requests (default: 10).
  • --verb HTTP method to use (GET or POST, default: GET).
  • --jsonpath Path to the JSON file to use as the body for POST requests.
  • --rand-id-type Type of random id to generate (number or string).
  • --rand-id-chrs Number of characters or digits for the random id.

Example Scenarios

GET Request with Concurrency

docker run --rm restclient \
  --url=http://example.com/ \
  --requests=100 \
  --concurrency=20

POST Request with a JSON Body

docker run --rm \
  -v /path/to/your/jsonfiles:/app/jsonfiles \
  restclient:latest \
  --url=http://example.com/api/resource \
  --requests=50 \
  --concurrency=5 \
  --verb=POST \
  --jsonpath=/app/jsonfiles/body.json

POST Request with Random ID Generation

docker run --rm \
  -v /path/to/your/jsonfiles:/app/jsonfiles \
  restclient:latest \
  --url=http://example.com/api/resource \
  --requests=20 \
  --concurrency=10 \
  --verb=POST \
  --jsonpath=/app/jsonfiles/body.json \
  --rand-id-type=string \
  --rand-id-chrs=8

Conclusion

This tool is a simple and effective way to test the performance of your HTTP services. It supports both GET and POST requests, with the ability to customize the request body and add randomness for better simulation of real-world scenarios.

Summary of Changes:

  • Command Line Options: The section now includes a code block that lists each option with its description, making it easier to read and reference.
  • Consistency: Maintained consistent formatting throughout the README for clarity.
  • Examples: Provided multiple usage examples to demonstrate different scenarios.

License

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

# Packages

No description provided by the author