Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thatstoasty/mojo-http-client
Simple socket wrapper and http client for Mojo
https://github.com/thatstoasty/mojo-http-client
http-client mojo socket
Last synced: about 1 month ago
JSON representation
Simple socket wrapper and http client for Mojo
- Host: GitHub
- URL: https://github.com/thatstoasty/mojo-http-client
- Owner: thatstoasty
- License: mit
- Created: 2024-02-06T18:28:08.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-10T02:54:10.000Z (8 months ago)
- Last Synced: 2024-09-24T16:22:50.777Z (5 months ago)
- Topics: http-client, mojo, socket
- Language: Mojo
- Homepage:
- Size: 132 KB
- Stars: 16
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-mojo-max-mlir - thatstoasty/mojo-http-client - http-client?style=social"/> : Simple socket wrapper and http client for Mojo. (HTTP Framework)
- awesome-mojo-max-mlir - thatstoasty/mojo-http-client - http-client?style=social"/> : Simple socket wrapper and http client for Mojo. (HTTP Framework)
README
# mojo-http-client
![Mojo 24.4](https://img.shields.io/badge/Mojo%F0%9F%94%A5-24.4-purple)
A barebones HTTP/1.1 client for Mojo using only Mojo and external C calls.
Thanks to the following for a large chunk of the code for working with sockets via external calls to C!
- https://github.com/saviorand/lightbug_http/tree/main
- https://github.com/gabrieldemarmiesse/mojo-stdlib-extensions/tree/master## Usage
Currently, it's a simple client. It's able to send requests and parse response strings into a Response struct, and pass some data along.
```mojo
from http_client.client import HTTPClient, Headersfn test_post() raises:
var test = MojoTest("Testing client.post")# Add headers
var headers = Headers()
headers["Connection"] = "close"# Add data
var data = Dict[String, String]()
data["hello"] = "world"var response = HTTPClient().post("www.httpbin.org", "/post", headers=headers, data=data)
test.assert_equal(response.status_code, 200)
test.assert_equal(response.status_message, "OK")
test.assert_equal(response.headers["Content-Type"], "application/json")
test.assert_equal(response.scheme, "http")# Simple GET request
fn test_get() raises:
var test = MojoTest("Testing client.get")
var response = HTTPClient().get("www.example.com", "/", 80)
print(response)
test.assert_equal(response.status_code, 200)
test.assert_equal(response.status_message, "OK")
test.assert_equal(response.scheme, "http")
```## TODO
- Add SSL support
- Add HTTP/2 support
- Add tests
- Fix URI query params logic. String termination messes up the host name.