mmacedoeu / swapi

Rest Showcase

Home Page:https://swapi.ga

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Swapi

Build Status Language (Rust)

Swapi is a CRSD Create Read Search Delete show case for the following features:

Features

Not Featured

  • Json result paging
  • Authentication
  • database replication
  • Json error handling

Install

To compile and install you need to first install Rust compiler

curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain nightly-2018-05-10

Compile for release

cargo build --release

Platform support

Should compile and work on all rust compiler supported plataforms but only tested for 64bit linux

Docker support

There is a docker image on docker hub

docker pull mmacedoeu/swapi

docker run -p 8080:8080 mmacedoeu/swapi

Snapd support

Look for Snap install instructions for your OS and install swapi with:

sudo snap install swapi --channel=edge --devmode

Cloud support

Support for heroku based Cloud services with provided Procfile, should work on any cloud provider based on Heroku Procfile and with minor manifest files on any Cloud provider

Usage

Display help:

./target/release/swapi --help

Star Wars Api

USAGE:
    swapi [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -d <db>                 Specify the base database storage path.
    -e <expire>             Time in seconds for cache expiration. default 7 days. [default: 604800]
    -i <IP>                 Specify the hostname portion of the REST API server, IP should be an interface's IP address,
                            or all (all interfaces) or local. [default: local]
    -l <LOG_PATTERN>        Sets a custom logging
    -p <PORT>               Api tcp listener port, default to environment variable PORT or 8080

Run with full trace:

./target/release/swapi -l trace

Run with no logging:

./target/release/swapi -l warn,actix_web::middleware::logger=warn

Testing

Manual Testing

Manual Testing is done with your preferred http client cli like curl, Httpie, http-prompt, or any http test tool like postman

Read All

http :8080/sw

Search by name

http :8080/sw/?search=Tato

Get by id

http :8080/sw/<uuid> like http :8080/sw/0c298919-76f0-42d7-868b-0a0d70d14903

Delete

http DELETE :8080/sw/<uuid> like http DELETE :8080/sw/0c298919-76f0-42d7-868b-0a0d70d14903

Create

http POST :8080/sw name=Hoth climate=frozen terrain='tundra, ice caves, mountain ranges'

Load testing

Using Vegeta with 8 cores during 10 seconds and 5000 requests per second

For read all

echo "GET http://localhost:8080/sw" | vegeta attack -duration=10s -rate=5000 | tee results.bin | vegeta report -reporter=plot > plot.html

alt text

echo "GET http://localhost:8080/sw" | vegeta attack -duration=10s -rate=5000 | tee results.bin | vegeta report

Requests      [total, rate]            50000, 5000.10
Duration      [total, attack, wait]    10.000322134s, 9.999799929s, 522.205µs
Latencies     [mean, 50, 95, 99, max]  583.374µs, 457.817µs, 1.038971ms, 3.024058ms, 15.524554ms
Bytes In      [total, mean]            19950000, 399.00
Bytes Out     [total, mean]            0, 0.00
Success       [ratio]                  100.00%
Status Codes  [code:count]             200:50000
Error Set:

Get by id

echo "GET http://localhost:8080/sw/de09bbe9-a993-4ede-89aa-6713e8fc2976" | vegeta attack -duration=10s -rate=5000 | tee results.bin | vegeta report

Requests      [total, rate]            50000, 5000.10
Duration      [total, attack, wait]    10.00022721s, 9.999799894s, 427.316µs
Latencies     [mean, 50, 95, 99, max]  477.733µs, 396.327µs, 785.652µs, 2.179568ms, 11.341423ms
Bytes In      [total, mean]            6850000, 137.00
Bytes Out     [total, mean]            0, 0.00
Success       [ratio]                  100.00%
Status Codes  [code:count]             200:50000  
Error Set:

Search by name

echo "GET http://127.0.0.1:8080/sw/?search=Tato" | vegeta attack -duration=10s -rate=5000 | tee results.bin | vegeta report

Requests      [total, rate]            50000, 5000.10
Duration      [total, attack, wait]    10.000370959s, 9.999799882s, 571.077µs
Latencies     [mean, 50, 95, 99, max]  727.904µs, 482.15µs, 1.551523ms, 4.861028ms, 22.019851ms
Bytes In      [total, mean]            5650000, 113.00
Bytes Out     [total, mean]            0, 0.00
Success       [ratio]                  100.00%
Status Codes  [code:count]             200:50000
Error Set:

With histogram:

echo "GET http://127.0.0.1:8080/sw/?search=Tato" | vegeta attack -duration=10s -rate=5000 | tee results.bin | vegeta report -reporter='hist[0,1ms,2ms,3ms,4ms]'

Bucket         #      %       Histogram
[0s,    1ms]   46790  93.58%  ######################################################################
[1ms,   2ms]   1773   3.55%   ##
[2ms,   3ms]   624    1.25%
[3ms,   4ms]   297    0.59%
[4ms,   +Inf]  516    1.03%

About

Rest Showcase

https://swapi.ga


Languages

Language:Rust 100.0%