Skip to content

23prime/23prime-api

Repository files navigation

23prime-api

Rust CI

Backend Web API for 23prime-page.

Run

With Docker

$ docker-compose -f docker-compose.local.yml up

Only DB

$ docker-compose -f docker-compose.local.yml up postgres

Without Docker

$ cargo run

(Recommend) If using cargo-watch:

$ cargo watch -x run

Test, Lint and Format

Up DB

Some tests require DB connection, so you need up and migrate before testing.

$ docker-compose -f docker-compose.test.yml up -d --wait

Test

$ export DATABASE_URL=postgres://admin:password@localhost:5442/GKBDB
$ cargo run --manifest-path ./migration/Cargo.toml up
$ cargo test --all -- --nocapture --test-threads=1

Lint

$ cargo fmt --all -- --check

Format

$ cargo clippy --all-targets --all-features -- -D warnings -A clippy::needless_return

Check all

$ chmod +x check.sh
$ ./check.sh

Build and Deploy

$ aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/m0z8x5y6
$ docker-compose build
$ docker push public.ecr.aws/m0z8x5y6/okkey-api:latest

Environment variables

Make .env and add some variables. See .env.template.

Migrate by SeaORM

See:

Create

$ cd migration/
$ target/debug/migration generate <migration name>

Run

Check status:

$ migration/target/debug/migration status

And run:

$ migration/target/debug/migration up

Development

Install tools

If use only Docker, you need not to install these tools, because there are already installed in Dockerfile-local.

$ rustup component add rustfmt
$ rustup component add clippy
$ cargo install cargo-watch cargo-edit

Authorization

Authorized with Authorization Code Flow by Auth0.

Access to My URL: https://23prime.xyz

Then, redirect to /auth/callback and get access token:

{
    id: "{your id}",
    token: "{access token}"
}

You can send API request with the header Authorization: Bearer {access_token}.

APIs

/api/index

Method Require Auth
GET o

GET

  • Response Body
Hello, Anime API!!

/api/echo

Method Require Auth
GET o
POST o

GET

  • Response Body
{your request body}

POST

  • Response Body
{your request body}

/api/animes/:year/:season

Method Require Auth
GET o

GET

  • Params
Param Kind Type Required remarks
year path integer false
season path string false spring|summer|fall|winter
  • Response Body
{
    "animes": [
        {
            "id": {id},
            "year": {YYYY},
            "season": "{spring|summer|fall|winter}",
            "day": "{Sun|Mon|Tue|Wed|Thu|Fri|Sat}",
            "time": "hh:mm",
            "station": "{station}",
            "title": "{title}",
            "recommend": {true|false}
        },
        // and more...
    ]
}

POST

  • Params
Param Kind Type Required remarks
id body integer true
year body integer true
season body string true
day body string true
time body string true
station body string true
title body string true
recommend body bool true
  • Response Body
{
    "animes": [
        {
            "id": {id},
            "year": {YYYY},
            "season": "{spring|summer|fall|winter}",
            "day": "{Sun|Mon|Tue|Wed|Thu|Fri|Sat}",
            "time": "hh:mm",
            "station": "{station}",
            "title": "{title}",
            "recommend": {true|false}
        },
        // and more...
    ]
}

PUT

  • Params
Param Kind Type Required remarks
id body integer true
year body integer true
season body string true
day body string true
time body string true
station body string true
title body string true
recommend body bool true
  • Response Body
{
    "animes": [
        {
            "id": {id},
            "year": {YYYY},
            "season": "{spring|summer|fall|winter}",
            "day": "{Sun|Mon|Tue|Wed|Thu|Fri|Sat}",
            "time": "hh:mm",
            "station": "{station}",
            "title": "{title}",
            "recommend": {true|false}
        },
        // and more...
    ]
}

DELETE

  • Params
Param Kind Type Required remarks
id body integer true
year body integer true
season body string true
day body string true
time body string true
station body string true
title body string true
recommend body bool true
  • Response Body
{
    "animes": [
        {
            "id": {id},
            "year": {YYYY},
            "season": "{spring|summer|fall|winter}",
            "day": "{Sun|Mon|Tue|Wed|Thu|Fri|Sat}",
            "time": "hh:mm",
            "station": "{station}",
            "title": "{title}",
            "recommend": {true|false}
        },
        // and more...
    ]
}

/scrape/:season

Method Require Auth
GET o

GET

  • Params
Param Kind Type Required remarks
season path string true spring|summer|fall|winter
  • Response Body
{
    "animes": [
       {
            "title": "{title}",
            "year": {current year (YYYY)},
            "season": "{spring|summer|fall|winter}",
            "wday": "{Sun|Mon|Tue|Wed|Thu|Fri|Sat}",
            "time": "hh:mm",
            "station": "{station}"
        },
        // and more...
    ]
}

Releases

No releases published

Packages

No packages published

Languages