update readme

This commit is contained in:
Adrien Marquès 2018-11-29 19:58:03 +01:00
parent 6274a72fb6
commit 3d38629167
1 changed files with 40 additions and 27 deletions

View File

@ -1,22 +1,54 @@
# | API mixer | # | API mixer |
Simple REST API mixer as a service. A minimal service will be deployed on your local port `8000`, all incoming data has to be sent by _POST_ fields (_e.g. [form-data](https://tools.ietf.org/html/rfc2388), [x-www-form-urlencoded](https://www.w3.org/TR/html5/sec-forms.html#urlencoded-form-data)_). The output is a _application/json_ set. Simple REST API mixer as a service. A minimal service will be deployed on your local port `8000`, the keywords has to be sent with the _query_ field `q`. The output is a _application/json_ set, if the header `Accept: application/json` is not set or does not specify json, it will render as a simplistic HTML webpage representing the results and images.
### Project Set up ### Summary
##### Prerequisites <!-- toc -->
- [I. Prerequisites](#i-prerequisites)
- [II. Easy Setup](#ii-easy-setup)
- [III. Test the API](#iii-test-the-api)
- [IV. Detailed Setup](#iv-detailed-setup)
+ [1. Transpile sources](#1-transpile-sources)
+ [2. Launch server](#2-launch-server)
<!-- tocstop -->
### I. Prerequisites
You need `node` and `npm` installed. The project is written using `typescript` that allows type checking and other verifications before creating the real javascript code. Also it adds polyfills (c.f. babel) to ECMAScript that allows the use of `class` and other new ES features. You need `node` and `npm` installed. The project is written using `typescript` that allows type checking and other verifications before creating the real javascript code. Also it adds polyfills (c.f. babel) to ECMAScript that allows the use of `class` and other new ES features.
##### 1. Install dependencies Then run the following command at the project's root to install necessary dependencies :
Go into the project's folder and run :
```bash ```bash
$ npm i $ npm i
``` ```
##### 2. Transpile sources
### II. Easy Setup
This command will build and run the whole project :
```bash
$ npm run build;
$ npm start;
```
### III. Test the API
You can now use [Postman](https://www.getpostman.com/) or whatever API client or web browser at `127.0.0.1:8000`. The only allowed request method is **GET** and accepts the research field in a query parameter named 'q'.
The console running the server will provide reactive and real-time details.
Example URL : http://127.0.0.1:8080/?q=Nutella that searches for the keyword "Nutella".
> When called in a browser you will get a simple web page that is the representation of the results (with images).
>
> When called with the header `Accept: application/json`, the result will represent the data as a JSON object.
### IV. Detailed Setup
##### 1. Transpile sources
Run the following command inside the project's folder : Run the following command inside the project's folder :
```bash ```bash
@ -27,7 +59,7 @@ All source files of the `src/` folder will be transpiled into the `dist/` folder
> It is also possible to watch the typescript while developping and modifying files with the command `npm run watch`. > It is also possible to watch the typescript while developping and modifying files with the command `npm run watch`.
##### 3. Launch server ##### 2. Launch server
> You need to have `node` installed. > You need to have `node` installed.
@ -35,22 +67,3 @@ Launch the server with the following command (inside the project's folder) :
```bash ```bash
$ node dist/main.js $ node dist/main.js
``` ```
### Project fast start
This command will build and run the whole project :
```bash
$ npm run build;
$ npm start;
```
### Test the API
You can now use [Postman](https://www.getpostman.com/) or whatever API client or web browser at `127.0.0.1:8000`. The only allowed request method is **GET** and accepts the research field in a query parameter named 'q'.
The console running the server will provide reactive and real-time details.
Example URL : http://127.0.0.1:8080/?q=Nutella that searches for the keyword "Nutella".
> When called in a browser you will get a simple web page that is the representation of the results (with images).
>
> When called with the header `Accept: application/json`, the result will represent the data as a JSON object.