https://github.com/toitlang/pkg-http
Package: Implement your REST server or client in Toit and run it on your ESP32.
https://github.com/toitlang/pkg-http
esp32 toit
Last synced: 8 months ago
JSON representation
Package: Implement your REST server or client in Toit and run it on your ESP32.
- Host: GitHub
- URL: https://github.com/toitlang/pkg-http
- Owner: toitlang
- License: mit
- Created: 2021-12-01T15:21:58.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2025-03-13T08:56:52.000Z (10 months ago)
- Last Synced: 2025-03-13T09:37:30.755Z (10 months ago)
- Topics: esp32, toit
- Language: Toit
- Homepage:
- Size: 318 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Toit package: http
An HTTP server and client.
This package implements the HTTP/1.1 protocol. It supports 'GET' and 'POST'
requests with convenience methods, and can be used to implement REST servers.
It has support for HTTPS connections. See the 'tls' examples for details.
## Examples
### Get request
```
import http
import net
main:
network := net.open
client := http.Client network
response := client.get "www.example.com" "/"
data := #[]
while chunk := response.body.read:
data += chunk
print data.to_string
client.close
```
### JSON Post request
This example encodes the data to the server with JSON and then decodes
the response as JSON as well.
```
import http
import net
import encoding.json
URL ::= "httpbin.org"
PATH ::= "/post"
main:
network := net.open
client := http.Client network
response := client.post_json --host=URL --path=PATH {
"foo": 42,
"bar": 499,
}
data := json.decode_stream response.body
client.close
print data
```