Skip to content

Commit 68bacf2

Browse files
committed
docs: add notes on curl
1 parent e2d8014 commit 68bacf2

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

chapter03/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,32 @@
44
* [localtunnel.github.io](https://localtunnel.github.io/) - Localtunnel allows you to easily share a web service on your local development machine without messing with DNS and firewall settings.
55
* [ngrok.com](https://ngrok.com/) - Spend more time programming. One command for an instant, secure URL to your localhost server through any NAT or firewall.
66

7+
## cURL
8+
We can use the `curl` command-line tool to interacte with Flask API.
9+
10+
### Example commands
11+
Get the current led brightness value
12+
> `$ curl -X GET http://localhost:5000/led`
13+
14+
Set the new value for led brightness
15+
> `$ curl -X POST -d '{"level": 100}' -H "Content-Type: application/json" http://localhost:5000/led`
16+
17+
### cURL options for GET
18+
`curl -X GET [options] [URL]`
19+
* `-X GET`: The HTTP request method that will be used when communicationg with the remote server
20+
* `URL`: The URL to request
21+
22+
### cURL options for POST
23+
`curl -X POST [options] [URL]`
24+
* `-X POST`: The HTTP request method that will be used when communicationg with the remote server
25+
* `-d`: This is the data we want to POST to the server, in our case it is in json format
26+
* `-H`: To set a specific header or Content-Type.
27+
In our example we are setting POST request type to `application/json`, to let our server know that the data we are sending is a JSON object
28+
* `URL`: The URL to request
29+
30+
31+
32+
733
## Virtual environment set up for this chapter<br>
834
> `$ python3 -m venv venv`<br>
935
> `$ source venv/bin/activate`<br>

0 commit comments

Comments
 (0)