https://github.com/jonathan-foucher/zap-api-example
An example of Zig API with Zap
https://github.com/jonathan-foucher/zap-api-example
zap zig
Last synced: 11 months ago
JSON representation
An example of Zig API with Zap
- Host: GitHub
- URL: https://github.com/jonathan-foucher/zap-api-example
- Owner: jonathan-foucher
- Created: 2024-11-16T23:30:07.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-05-07T12:45:52.000Z (about 1 year ago)
- Last Synced: 2025-05-07T13:46:13.929Z (about 1 year ago)
- Topics: zap, zig
- Language: Zig
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Introduction
This project is an example of a Zig API using Zap, libpq and a postgres database.
## Run the project
### Database
Install postgres locally or run it through docker with :
```
docker run -p 5432:5432 -e POSTGRES_DB=my_database -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres postgres
```
### Application
Once the postgres database is started, you can build and start the Zig project and try it out.
Build the application
```
zig build
```
Start the application (built executable)
```
zig-out/bin/zap_api_example
```
Get all the movies
```
curl --location 'http://localhost:3000/api/movies'
```
Save a movie
```
curl --request POST \
--url http://localhost:3000/api/movies \
--header 'Content-Type: application/json' \
--data '{
"id": 26,
"title": "Some movie title",
"release_date": "2022-02-26"
}'
```
Delete a movie
```
curl --request DELETE \
--url http://localhost:3000/api/movies/26
```