Python: Testing your REST API
This documentation is part of the Creating a REST API guide. You can view the complete guide here: Step-by-step guide to building a REST API with Flask in Python.
👋 Welcome to the Stackhero documentation!
Stackhero offers a ready-to-use Python cloud solution designed to simplify your deployments:
- Deploy your application to production in just seconds with a simple
git push.- Use your own domain name, with automatic HTTPS certificate setup for secure connections managed for you.
- Take advantage of automatic backups, one-click updates, and predictable pricing, so you can focus on your code instead of infrastructure management.
- Benefit from high performance and security on a private, dedicated infrastructure. Your environment is isolated and protected.
Save time and streamline your workflow: your code can be up and running with Stackhero's Python cloud hosting in just 5 minutes.
Once the server is running, you can interact with your API using cURL. Here are some example commands:
-
Retrieve all tasks:
curl -s http://localhost:8080/api/tasks # Output: # { # "tasks": [ # ... # ] # } -
Retrieve a specific task (ID 2):
curl -s http://localhost:8080/api/tasks/2 # Output: # { # "task": { # ... # } # } -
Create a new task:
curl -s -X POST -H "Content-Type: application/json" \ -d '{"title": "New task", "description": "Created with cURL"}' \ http://localhost:8080/api/tasks # Output: # { # "task": { # ... # } # }
Tip: For more readable output, you can pipe the result to
jq. For example,curl -s http://localhost:8080/api/tasks/2 | jqmakes the JSON easier to read.
Example of Python REST API using Flask, running in Stackhero Code-Hero, with the server (1) and the client using cURL (2)