an attempt to learn how to use rust for a web server
Check src/main.rs for all API endpoints.
See review-ssh for a terminal user interface.
https://review-api.fly.dev
| Public endpoints |
|---|
All GET endpoints except for GET /auth |
POST /users to create a new user |
All other endpoints require authentication. This means the id cookie received from POST /auth needs to be sent with each request. This happens automatically if using a browser.
Example with curl
curl --location --request GET 'https://review-api.fly.dev/auth' \
--header 'Cookie: id=YOUR_SESSION_ID'Check current user. This shows the email field.
{
"id": 1,
"name": "Kyle",
"email": "[email protected]",
"created_at": "2022-11-30T17:05:36.313355Z",
"updated_at": "2022-11-30T17:05:36.313355Z"
}This logs out the user.
204 OK
{
"email": "[email protected]",
"password": "password"
}This logs in the user.
| Key | Value |
|---|---|
| set-cookie | id=YOUR_SESION_ID_COOKIE; Path=/; Secure; HttpOnly; |
{
"id": 1,
"name": "Kyle Zheng",
"email": "[email protected]",
"created_at": "2022-11-30T20:03:35.554592Z",
"updated_at": "2022-11-30T20:03:35.554592Z"
}| Param | Type | Default |
|---|---|---|
| page | 0 < integer | 1 |
| per_page | 0 < integer < 51 | 10 |
| sort_by | FIELD.ORDERFIELD is one of id, name, created_at, updated_atORDER is one of asc, desc |
id.asc |
{
"results": [
{
"id": 1,
"name": "Kyle",
"created_at": "2022-11-30T17:05:36.313355Z",
"updated_at": "2022-11-30T17:05:36.313355Z"
},
{
"id": 3,
"name": "Loid",
"created_at": "2022-11-30T17:13:11.250255Z",
"updated_at": "2022-11-30T17:27:53.894057Z"
}
],
"page": 1,
"total_pages": 1,
"total_results": 2
}{
"id": 1,
"name": "Kyle",
"created_at": "2022-11-30T17:05:36.313355Z",
"updated_at": "2022-11-30T17:05:36.313355Z"
}This creates a new user.
{
"name": "Twilight",
"email": "[email protected]",
"password": "password"
}{
"id": 3,
"name": "Twilight",
"created_at": "2022-11-30T17:13:11.250255Z",
"updated_at": "2022-11-30T17:13:11.250255Z"
}All fields are optional.
{
"name": "Loid",
"email": "[email protected]"
}This shows the email field, because the route is authenticated.
{
"id": 3,
"name": "Loid",
"email": "[email protected]",
"created_at": "2022-11-30T17:13:11.250255Z",
"updated_at": "2022-11-30T17:27:53.894057Z"
}{
"deleted": 1
}Category is Film | Show
This mostly just a wrapper around the The Movie Database (TMDB) API.
| Param | Type | Default |
|---|---|---|
| page | 0 < integer | 1 |
| lang | ISO 639-1 value | en-US |
| year | integer | n/a |
{
"page": 1,
"results": [
{
"id": 505642,
"title": "Black Panther: Wakanda Forever",
"original_title": "Black Panther: Wakanda Forever",
"original_language": "en",
"release_date": "2022-11-09",
"overview": "Queen Ramonda, Shuri, M’Baku, Okoye and the Dora Milaje fight to protect their nation from intervening world powers in the wake of King T’Challa’s death. As the Wakandans strive to embrace their next chapter, the heroes must band together with the help of War Dog Nakia and Everett Ross and forge a new path for the kingdom of Wakanda.",
"poster_path": "/sv1xJUazXeYqALzczSZ3O6nkH75.jpg"
}
],
"total_results": 1,
"total_pages": 1
}| Param | Type | Default |
|---|---|---|
| page | 0 < integer | 1 |
| per_page | 0 < integer < 51 | 10 |
| sort_by | FIELD.ORDERFIELD is one of tmdb_id, created_at, updated_atORDER is one of asc, desc |
updated_at.desc |
| user_id | user id | n/a |
| category | Film | Show |
n/a |
| tmdb_id | tmdb_id integer | n/a |
| season | season integer | n/a |
| status | Completed | Watching | Dropped | PlanToWatch |
n/a |
| fun_before | bool | n/a |
| fun_during | bool | n/a |
| fun_after | bool | n/a |
{
"results": [
{
"user_id": 1,
"tmdb_id": 505642,
"category": "Film",
"status": "Completed",
"text": "🙅🏿♂️",
"fun_before": true,
"fun_during": true,
"fun_after": true,
"created_at": "2022-11-30T18:09:58.829342Z",
"updated_at": "2022-11-30T18:18:00.720356Z"
}
],
"page": 1,
"total_pages": 1,
"total_results": 1
}{
"tmdb_id": 505642,
"category": "Film",
"status": "Completed"
}
or
{
"tmdb_id": 505642,
"category": "Show",
"season": 1,
"status": "Completed"
}{
"user_id": 1,
"tmdb_id": 505642,
"category": "Film",
"status": "Completed",
"text": "",
"fun_before": false,
"fun_during": false,
"fun_after": false,
"created_at": "2022-11-30T18:09:58.829342Z",
"updated_at": "2022-11-30T18:09:58.829342Z"
}All fields are optional.
{
"status": "Completed",
"text": "🙅🏿♂️",
"fun_before": true,
"fun_during": true,
"fun_after": true
}{
"user_id": 1,
"tmdb_id": 505642,
"category": "Film",
"status": "Completed",
"text": "🙅🏿♂️",
"fun_before": true,
"fun_during": true,
"fun_after": true,
"created_at": "2022-11-30T18:09:58.829342Z",
"updated_at": "2022-11-30T18:18:00.720356Z"
}{
"deleted": 1
}- user auth
- search movies and shows using TMDB api
- add and edit reviews for movies and shows
- allow better programmatic access to api
- regeneratable api keys for users?
-
For basic structure
-
For refactor and advanced stuff
-
For diesel
- https://github.com/actix/examples/tree/master/databases/diesel
- https://kitsu.me/posts/2020_05_24_custom_types_in_diesel
- basically, just use
diesel-derive-enum
- basically, just use
- https://github.com/diesel-rs/diesel/tree/master/examples/postgres/advanced-blog-cli
-
For containerizing
- https://blog.logrocket.com/packaging-a-rust-web-service-using-docker/
- https://hub.docker.com/r/ekidd/rust-musl-builder/
- Not reading the README caused me to waste an entire day debugging. TLDR include
openssl_probe::init_ssl_cert_env_vars();to make OpenSSL work (for making outward requests).
- Not reading the README caused me to waste an entire day debugging. TLDR include
Look at .env.sample for template.
sudo service postgresql start
sudo service redis-server start
sudo -u postgres psql
redis-cli
docker build -t review-api:latest .
# .env.dev should have localhost replaced with host.docker.internal
docker run --rm -p 8080:8080 --env-file .env.dev review-apiDiesel reads DATABASE_URL in .env
check out db
psql -h <hostname> -p <port> -U <username> -d <database>