# JSON Pusher JSON Pusher is a simple command-line tool written in Rust that reads a JSON file, iterates over the objects within, and pushes each object to a specified API endpoint. The tool allows you to specify the API URL, request method (e.g., POST, PUT), and an optional bearer token for authorization. ## Features - Supports POST and PUT requests: Push JSON data using the HTTP method of your choice. - Bearer Token Support: Easily include a bearer token for authentication. - Iterates Over JSON Objects: Handles JSON arrays by sending each object as a separate request. - Cross Platform ## Installation #### Prerequisites Ensure you have [Rust](https://www.rust-lang.org/) installed on your machine. If not, you can install it via [rustup](https://rustup.rs/). ```sh curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh ``` #### Cloning the repo ```sh git clone https://github.com/th0jensen/json_pusher.git cd json_pusher ``` #### Building the Project To build the project, navigate to the project directory and run: ```sh cargo build --release ``` The compiled binary will be located in the target/release/ directory. #### Add to PATH (optional) ```sh cargo install --path . ``` ## Usage/Examples You can run the JSON Pusher using the following command: ```sh json_pusher --json --url --method [--token ] ``` #### Required Arguments - --json (-j): Path to the input JSON file. This file should contain an array of JSON objects. - --url (-u): The API endpoint URL where the JSON objects will be sent. - --method (-m): The HTTP method to use (e.g., POST, PUT). #### Optional Arguments - --token (-t): Path to a file containing the bearer token for authorization. If not provided, the requests will be sent without an Authorization header. ### Example ```sh json_pusher --json ./data/input.json --url https://api.example.com/endpoint --method POST --token ./data/token.txt ``` This command will: 1. Read the JSON objects from input.json. 2. Iterate over each object and send it as a POST request to https://api.example.com/endpoint. 3. Include the bearer token from token.txt in the Authorization header of each request. #### Sample JSON File Here’s an example of what your JSON file might look like: ```json [ { "id": 1, "name": "Object 1" }, { "id": 2, "name": "Object 2" } ] ``` Each object in the array will be sent as a separate request to the specified API endpoint. #### Error Handling - Unsupported HTTP Method: The tool currently supports only POST and PUT methods. If an unsupported method is specified, the program will exit with an error. - File Reading Errors: If the JSON file or token file cannot be read, an error will be displayed, and the program will terminate. ## Contributing Contributions are welcome! If you find a bug or have a feature request, please open an issue or submit a pull request. ## License This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for more details.