An open API service indexing awesome lists of open source software.

https://github.com/tobie-rathbun/restful_api--method-testing

A RESTful API built in PHP that listens to calls from a desktop Python application
https://github.com/tobie-rathbun/restful_api--method-testing

Last synced: about 1 year ago
JSON representation

A RESTful API built in PHP that listens to calls from a desktop Python application

Awesome Lists containing this project

README

          

Tools Summary:

PHP API (api.php):
Purpose: Handles incoming POST requests, processes JSON data, and stores items in a file (items.txt).
Key Feature: Responds with a success message if the item is created.

Python Script:
Purpose: Sends a POST request to the PHP API (api.php).
Key Features: Uses the requests library to send a POST request with JSON data. Displays response details.

How to Use:
Setting Up the PHP API (api.php):

Install XAMPP:
Install XAMPP on your machine.

Copy to htdocs:
Place the provided my_api folder inside the htdocs directory of your XAMPP installation.

Running the Python Script:

Check API URL:
Ensure the URL in the Python script points to your PHP API (http://localhost/my_api/api.php).

Install Required Package:
If not installed, run pip install requests to install the requests library.

Execute Script:
Run the Python script from the terminal using python your_script_name.py.

Review Output:
Check the terminal output for information on the request and response.

Testing with Simple Rest Client in VS Code:

Install Simple Rest Client:
Install the "REST Client" extension in VS Code.

Open Simple Rest Client:
Click on the "Send Request" link in your Python script file.

Configure Request:
Set the method to POST.
Enter the URL as http://localhost/my_api/api.php.

Headers and Body:
Configure headers if needed.
Enter JSON data in the body (e.g., {"item": "Test Item"}).

Send Request:
Click the "Send Request" button.

Review Response:
Check the response in the client for the status, message, and item details
Alternatively look at the updated .txt C:/xampp/htdocs/my_api/items.txt