duyet / glossary-rs

Glossary API Service written in Rust, powered by actix.rs and diesel.rs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Glossary Logo

Glossary API

Open-Source Glossary API Service written in Rust, powered by https://actix.rs and https://diesel.rs.

Endpoints

Method Endpoint What it does
GET /api/v1/glossary Returns a dictionary of glossary with key is the first character of glossary terms.
GET /api/v1/glossary-popular Returns an array of most popular terms by likes.
GET /api/v1/glossary/{id} Return the glossary term and defintion.
POST /api/v1/glossary Create a new glossary with term and defintion.
PUT /api/v1/glossary/{id} Update a glossary.
DELETE /api/v1/glossary/{id} Delete a glossary.
GET /api/v1/glossary/{id}/likes Return an array of likes for a glossary.
POST /api/v1/glossary/{id}/likes Create a like for a glossary.
DELETE /api/v1/glossary/{id}/likes Delete a like from a glossary.

Development

Prerequisites

  • Rust >= 1.26
  • PostgreSQL >= 9.5

Set up the database

Install the diesel command-line tool including the postgres feature

cargo install diesel_cli --no-default-features --features postgres

Check the contents of the .env file. If your database requires a password, update DATABASE_URL to be of the form:

DATABASE_URL=postgres://username:password@localhost/glossary

Tip: on MacOS, please prefer to use https://postgres.app

Then to create and set-up the database run:

diesel database setup

Migrate database schema:

diesel migration run

Run the application

To run the application execute:

cargo run

Then open in your browser: http://localhost:8080

Tests

To run the unittest, make sure to have Postgres installed in your machine. Please export TEST_DATABASE_URL=postgres://localhost:5432 to your Postgres instance.

  • On the MacOS, the easiest way is install https://postgres.app
  • Otherwise, you can start Postgres by Docker Compose:
    docker-compose up -d
    

To run the unittest:

cargo test

Deployment

Using Docker image

Deploy using docker image from https://github.com/duyet/glossary/pkgs/container/glossary

docker run -it \
  -e DATABASE_URL=postgres://postgres:5432/glossary \
  -p 8080:8080 \
  ghcr.io/duyet/glossary:0.1.0

Using Helm chart

TBU

Building Docker image from source

Build and deploy by using docker:

docker build -t glossary .
docker run -it \
  -e DATABASE_URL=postgres://postgres:5432/glossary \
  -p 8080:8080 \
  glossary 

License

MIT

About

Glossary API Service written in Rust, powered by actix.rs and diesel.rs.

License:MIT License


Languages

Language:Rust 89.8%Language:Shell 7.7%Language:PLpgSQL 1.8%Language:Dockerfile 0.6%