An API for H.P. Lovecraft's Works' Electronic Texts.
In order for the server to function properly, you need initialize the database and set some environment variables.
Database (RDBMS being SQLite in this case) can have a table defined in the following way:
CREATE TABLE IF NOT EXISTS manuscript (
id INTEGER PRIMARY KEY NOT NULL,
category TEXT NOT NULL,
title TEXT NOT NULL UNIQUE,
content TEXT NOT NULL,
description TEXT NOT NULL
);
You can then insert any data that you like (preferably public domain H.P. Lovecraft's works), like so:
INSERT INTO manuscript (category, title, content, description)
VALUES ('Category', 'The Title', 'The content of the manuscript.', 'The description of the manuscript.');
As for the environment variables, here is an example (.env
file):
HOST=127.0.0.1
PORT=3000
DATABASE_URL="sqlite://database/manuscript.db"
RUST_LOG=lovecraft_api=info,actix=info,actix_web=info
CERTIFICATE="cert.pem"
CERTIFICATE_KEY="key.pem"
Regarding routes, please visit the /api/v1/manuscripts
endpoint for the main content!
Available routes:
- GET
/manuscripts
-> array of entry objects consisting of: id, category, title, description - GET
/manuscripts/{id}
-> manuscript object consisting of: id, category, title, content
For the complete API design and documentation (does not fully match the application's functionality in terms of error results), you can take a look at the OpenAPI Specification based API documentation.
Finally, mkcert
is used to issue local certificates to enable https
(by first running mkcert -install
and then mkcert -key-file key.pem -cert-file cert.pem localhost 127.0.0.1 ::1
). You can disable the certificate functionality altogether by putting the following code instead of the existing one in main.rs
and then removing the unnecessary leftover code:
server.bind(format!("{}:{}", host, port))?
Here are the sample responses:
/manuscripts
:
[
{
"id": 1,
"category": "Category",
"title": "The Title",
"description": "The description of the manuscript."
},
{
"id": 2,
"category": "Category",
"title": "The Title",
"description": "The description of the manuscript."
}
]
/manuscripts/1
:
{
"id": 1,
"category": "Category",
"title": "The Title",
"content": "The content of the manuscript."
}
In order to build lovecraft-api, you need to have Rust programming language installed on your system. To install Rust (alongside Cargo, which comes bundled with Rust), it's best to follow the official installation steps.
It is preferred to build the project with Rust version 1.44.1 (c7087fe00 2020-06-17).
# Clone the repository
git clone https://github.com/GiorgiBeriashvili/lovecraft-api
cd lovecraft-api
# Build the debug version
cargo build
lovecraft-api is licensed under either of the following, at your option:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)