An open API service indexing awesome lists of open source software.

https://github.com/duyet/glossary-rs

Glossary API Service written in Rust, powered by actix.rs and diesel.rs.
https://github.com/duyet/glossary-rs

actix actix-web diesel-rs hacktoberfest postgres postgresql rust

Last synced: about 2 months ago
JSON representation

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

Awesome Lists containing this project

README

        


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

```bash
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:

```bash
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:

```bash
diesel database setup
```

Migrate database schema:

```bash
diesel migration run
```

## Run the application

To run the application execute:

```bash
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

```bash
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:

```bash
docker build -t glossary .
```

```bash
docker run -it \
-e DATABASE_URL=postgres://postgres:5432/glossary \
-p 8080:8080 \
glossary
```

# License

MIT