api-mixer/README.md

70 lines
2.3 KiB
Markdown
Raw Normal View History

2018-10-17 15:58:13 +00:00
# | API mixer |
2018-10-17 14:02:29 +00:00
2018-11-29 18:58:03 +00:00
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.
2018-10-17 15:58:13 +00:00
2018-11-29 18:58:03 +00:00
### Summary
2018-10-17 15:58:13 +00:00
2018-11-29 18:58:03 +00:00
<!-- toc -->
2018-10-17 15:58:13 +00:00
2018-11-29 18:58:03 +00:00
- [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)
2018-10-22 15:40:56 +00:00
2018-11-29 18:58:03 +00:00
<!-- tocstop -->
2018-10-22 15:40:56 +00:00
2018-11-29 18:58:03 +00:00
### I. Prerequisites
2018-10-22 15:40:56 +00:00
2018-11-29 18:58:03 +00:00
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.
2018-10-17 15:58:13 +00:00
2018-11-29 18:58:03 +00:00
Then run the following command at the project's root to install necessary dependencies :
2018-10-17 15:58:13 +00:00
```bash
2018-11-29 18:58:03 +00:00
$ npm i
2018-10-17 15:58:13 +00:00
```
2018-11-29 18:58:03 +00:00
### II. Easy Setup
2018-10-22 15:44:37 +00:00
2018-10-22 15:52:29 +00:00
This command will build and run the whole project :
```bash
$ npm run build;
$ npm start;
```
2018-11-29 18:58:03 +00:00
### III. Test the API
2018-10-17 15:58:13 +00:00
2018-11-19 13:22:57 +00:00
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'.
2018-11-19 13:29:11 +00:00
The console running the server will provide reactive and real-time details.
2018-11-19 13:22:57 +00:00
2018-11-19 13:29:11 +00:00
Example URL : http://127.0.0.1:8080/?q=Nutella that searches for the keyword "Nutella".
2018-11-19 13:22:57 +00:00
> When called in a browser you will get a simple web page that is the representation of the results (with images).
>
2018-11-29 18:58:03 +00:00
> 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 :
```bash
$ npm run build
```
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`.
##### 2. Launch server
> You need to have `node` installed.
Launch the server with the following command (inside the project's folder) :
```bash
$ node dist/main.js
```