Skip to content

An API for H.P. Lovecraft's Works' Electronic Texts.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

GiorgiBeriashvili/lovecraft-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lovecraft-api

LICENSE

Description

An API for H.P. Lovecraft's Works' Electronic Texts.


Usage

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:https://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."
}

Building

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

License

lovecraft-api is licensed under either of the following, at your option:

About

An API for H.P. Lovecraft's Works' Electronic Texts.

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages