This is an HTTP server written in ZIG from scratch, that allows you to do CRUD operation on a contact server, serving just the backend Ideally, this should be able to handle request from both browser and curl.
We typically get a HTTP request like so:
METHOD /path?query HTTP/1.1\r\n
Header-Name: Header-Value\r\n
Another-Header: value\r\n
\r\n
[optional body]
The main information is stored before the optional body. A parser needs to reliably parse this information, and respond to it appropriately.
A response would look something like this:
HTTP/1.1 200 OK\r\n
Content-Type: text/html\r\n
Content-Length: 42\r\n
\r\n
[body]
This is just a learning project, so it'll only support a subset of features provided by HTTP:
- GET
- POST
- DELETE
- PUT
- 2xx - Success:
200 OK,201 Created - 4xx - Client error:
400 Bad Request,401 Unauthorized,404 Not Found,405 Method Not Allowed - 5xx - Server Error:
500 Internal Server Error,501 Not Implemented
/: Gives you a good Programming introductoryHello World!screen/get-contact?contact=$: Gives you the contact's phone saved on db/del-contact: Deletes a contact from db/update-contact: updates an existing contact/upload-contact: Uploads a new contact. Errors if it already exists
Pre-requisite: Download zig from ther official website
Also, you'd probably wanna change the postgres db address in the following to make it fully work(env is a pain in the neck in zig rn):
Line 26 in b79a91b
Then, run to start the server:
make build_and_runAfter setting up the db and running the command, you should see this:
TCP listening on http://0.0.0.0:3636Go to the website, and have fun!