Skip to content

LoiKos/kituraAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

This API as been design to be used to test Swift Kitura framework performances.

This API is build to work with a PostgreSQL database and provide a way to interact with stores and products through an relational model.

Api Documentation

Stores | Products | Stock | Errors

Jazzy docs

Generate Jazzy docs under macOS :

run jazzy and .jazzy.yaml will do the rest

you can also pass some options see the official documentation Jazzy

access online docs : Docs

Stores

URL : api/v1/stores | api/v1/stores/:id

Method : GET,POST | DELETE , PATCH GET

URL Params :     none         |  id: required

Parameters :  Limit and Offet with GET | None

Request body Structure :

// Store obj
{
   "refStore": String   //  Auto generated do not modify
   "name": String,      //  required
   "picture":String,    //  optional
   "vat":Double,        //  optional
   "currency":String,   //  optional
   "merchantkey":String //  optional
} 

Code

Code: 200 OK

Content:

// Store obj
{
   "refStore": String   //  Auto generated do not modify
   "name": String,      //  required
   "picture":String,    //  optional
   "vat":Double,        //  optional
   "currency":String,   //  optional
   "merchantkey":String //  optional
} 

OR

[
   {
      "refStore": String   //  Auto generated do not modify
      "name": String,      //  required
      "picture":String,    //  optional
      "vat":Double,        //  optional
      "currency":String,   //  optional
      "merchantkey":String //  optional
   },{
      "refStore": String   //  Auto generated do not modify
      "name": String,      //  required
      "picture":String,    //  optional
      "vat":Double,        //  optional
      "currency":String,   //  optional
      "merchantkey":String //  optional
   }
   ,...
] 

Code: 201 CREATED

Content:

// Store obj
{
   "refStore": String   //  Auto generated do not modify
   "name": String,      //  required
   "picture":String,    //  optional
   "vat":Double,        //  optional
   "currency":String,   //  optional
   "merchantkey":String //  optional
} 

Products

URL : api/v1/products | api/v1/products/:id

Method : GET,POST | DELETE , PATCH GET

URL Params :     none         |  id: required

Parameters :  Limit and Offet with GET | None

Request body Structure :

// Product obj
{
   "refproduct": String //  Auto generated do not modify
   "name": String,      //  required
   "picture":String,    //  optional
   "creationdate":Date //  Auto generated do not modify
} 

Code

Code: 200 OK

Content:

// Product obj
{
   "refproduct": String //  Auto generated do not modify
   "name": String,      //  required
   "picture":String,    //  optional
   "creationdate":Date //  Auto generated do not modify
} 

OR

[
   // Product obj
{
   "refproduct": String //  Auto generated do not modify
   "name": String,      //  required
   "picture":String,    //  optional
   "creationdate":Date //  Auto generated do not modify
},{
   "refproduct": String //  Auto generated do not modify
   "name": String,      //  required
   "picture":String,    //  optional
   "creationdate":Date //  Auto generated do not modify
} 
   ,...
] 

Code: 201 CREATED

Content:

// Product obj
{
   "refproduct": String //  Auto generated do not modify
   "name": String,      //  required
   "picture":String,    //  optional
   "creationdate":Date //  Auto generated do not modify
} 

Stock

URL : api/v1/stores/:storeId/products | api/v1/stores/:storeId/products/:productId

Method : GET,POST | DELETE , PATCH GET

URL Params :     storeId: required         |  storeId: required, productId: required

Parameters :  Limit and Offet with GET | None

Request body Structure :

// Stock obj
{
   "product_refproduct": String //  Auto generated do not modify
   "product_name": String,      //  required
   "product_picture":String,    //  optional
   "product_creationdate":Date, //  Auto generated do not modify
   "refproduct":String,
   "refstore":String,
   "quantity":Int,
   "vat":Double,
   "priceht":Double,
   "status":String,
   "creationdate":Date,
   "lastupdate":Date
} 

Code

Code: 200 OK

Content:

// Stock obj
{
   "product_refproduct": String //  Auto generated do not modify
   "product_name": String,      //  required
   "product_picture":String,    //  optional
   "product_creationdate":Date, //  Auto generated do not modify
   "refproduct":String,
   "refstore":String,
   "quantity":Int,
   "vat":Double,
   "priceht":Double,
   "status":String,
   "creationdate":Date,
   "lastupdate":Date
} 

OR

[
   // Product obj
// Stock obj
{
   "product_refproduct": String //  Auto generated do not modify
   "product_name": String,      //  required
   "product_picture":String,    //  optional
   "product_creationdate":Date, //  Auto generated do not modify
   "refproduct":String,
   "refstore":String,
   "quantity":Int,
   "vat":Double,
   "priceht":Double,
   "status":String,
   "creationdate":Date,
   "lastupdate":Date
} ,{
   "product_refproduct": String //  Auto generated do not modify
   "product_name": String,      //  required
   "product_picture":String,    //  optional
   "product_creationdate":Date, //  Auto generated do not modify
   "refproduct":String,
   "refstore":String,
   "quantity":Int,
   "vat":Double,
   "priceht":Double,
   "status":String,
   "creationdate":Date,
   "lastupdate":Date
}
   ,...
] 

Code: 201 CREATED

Content:

// Stock obj
{
   "product_refproduct": String //  Auto generated do not modify
   "product_name": String,      //  required
   "product_picture":String,    //  optional
   "product_creationdate":Date, //  Auto generated do not modify
   "refproduct":String,
   "refstore":String,
   "quantity":Int,
   "vat":Double,
   "priceht":Double,
   "status":String,
   "creationdate":Date,
   "lastupdate":Date
}

API Error

Code: 400 BAD REQUEST

Example :

  • Empty JSON Body for POST or PATCH

  • Missing required properties POST

  • Wrong limit or offset ( < 0 )

Code: 404 NOT FOUND

Example : Id not found in database

Code: 500 INTERNAL SERVER ERROR

Work with Docker

Required images :

$ docker pull postgres
$ docker pull swift

Launch database container :

Run a docker container that contains a postgres database. With environnement variable you can specify the name of db, a username and a password

$ docker run --name *name* -e POSTGRES_PASSWORD=*pwd* -e POSTGRES_USER=*userName* -e POSTGRES_DB=*dbName* -d postgres

Build image :

Then lauch this command inside the project folder. If you want to set it  :

```shell 
$ docker build -t *name* . 

if your working behind a proxy you need to set proxy with '--build-arg' :

$ docker build --build-arg http_proxy=*yourproxy* --build-arg https-proxy=*yourhttpsproxy* -t *name* . 

please be careful about http_proxy and HTTP_PROXY you can have some issues if your not using it correctly. For example apt-get works fine with http_proxy but not with HTTP_PROXY

name correspond au nom que vous voulez donner à l'image

Launch kitura container :

$ docker run -it --rm --link *databaseContainerName*:database -p 8080:8080 -v `pwd`:`pwd` -w `pwd` *name*

if your application recover database settings through environnement variable please use -e options with run commands :

$ docker run -it --rm --link *databaseContainerName*:database -e DATABASE_USER=USER -p 8080:8080 -v `pwd`:`pwd` -w `pwd` *name*

you can also modify the 'Dockerfile' and add some lines to provide directly the ENV variables (NOT RECOMMENDED) :

# this is an example you have to make it match your application and database settings
ENV DATABASE_USER=USER
ENV DATABASE_DB=storeDB
ENV DATABASE_HOST=...

Code Coverage

Coming

Task Flow

  • Database connection
  • Stores routes
  • Products routes
  • Stock routes
  • Docker
  • Linux compatibility
  • API docs
  • Unit tests
  • CI
  • Code Cov

About

Kitura API for load testing

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages