From 35a216ca6972c2805bb8a626640901316a2a4eb4 Mon Sep 17 00:00:00 2001 From: sundowndev Date: Thu, 30 Aug 2018 11:15:19 +0200 Subject: [PATCH] [Docs] README --- README.md | 119 +++++++++++++++++++++++++++++++++------------ app.js => index.js | 0 2 files changed, 88 insertions(+), 31 deletions(-) rename app.js => index.js (100%) diff --git a/README.md b/README.md index cc2390c..b8b4bc2 100644 --- a/README.md +++ b/README.md @@ -1,52 +1,109 @@ # interview-v2 -Fetch posts using a REST API. +Simple REST API application based on Expressjs to fetch blog posts with custom endpoints and responses. + +### Installation (docker) + +~~~ +$ git clone +$ cd interview-v2/ +$ docker-compose build +~~~ ### Installation -... +~~~ +$ npm install +~~~ ### Usage -... +Launch server + +~~~ +$ node index.js +~~~ + +Launch application with Docker + +~~~ +$ docker-compose up -d +~~~ ### API endpoints -... - +| Method / Route | Resource | Description | +| --------------------- | ------------------ | ------------ | +| `GET` /posts | Posts,Users | Fetch posts and their users | + +The `/posts` route can receive extra parameters : + +| Parameter | Values/type | Description | +| --------------------- | ------------------ | ------------ | +| user_pos | eq,cancer,cap,arctic,antarctic | Search posts by user position | +| user_id | *int* | Search posts by user id | + ### Response -Example response for posts +The response follows the [Google JSON guide](https://google.github.io/styleguide/jsoncstyleguide.xml). + +**Success response return data** ```json -[ - { - "title": "

title

", - "body": "

body

", - "user": { - "id": 1, - "firstname": "Raphael", - "lastname": "Cerveaux", - "email": "raphael@crvx.fr", - "comments_count": 3, - "geopos": "latitude 23° 27' sud" +{ + "data": [ + { + "id": 1001, + "name": "Wing" } - }, - { - "title": "

title2

", - "body": "

body

", - "user": { - "id": 1, - "firstname": "Raphael", - "lastname": "Cerveaux", - "email": "raphael@crvx.fr", - "comments_count": 3, - "geopos": "latitude 23° 27' sud" - } - } -] + ] +} ``` +**Error response return error** + +```json +{ + "error": { + "code": 404, + "message": "ID not found" + } +} +``` + +Here is an example response for `/posts` : + +```json +{ + "data": [ + { + "id": 1, + "title": "

sunt aut facere repellat provident occaecati excepturi optio reprehenderit

", + "body": "

quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto

", + "user": { + "id": 1, + "firstname": "Raphael", + "lastname": "Cerveaux", + "email": "raphael@crvx.fr", + "comments_count": 3, + "pos": { + "lat": "-37.3159", + "lng": "81.1496" + } + } + } + ] +} +``` + +### Architecture + +The application fetch resources from an external REST API and formats the response for the end user. + +![](https://i.imgur.com/vRJhQMP.png) + +The Docker configuration is composed of 2 layers. It uses a node image to launch the app and Nginx. + ----- ## Exercice diff --git a/app.js b/index.js similarity index 100% rename from app.js rename to index.js