University Api
- Open your terminal and type :
git clone https://github.com/Ierofantis/uni-proxy
- When the process is completed then navigate to the project:
cd uni-proxy
- Please type:
docker-compose build
and after that type:
docker-compose up
- Now you are ready to use the uni-api proxy
I will provide the list of the urls that you can enter:
- http://localhost:9000/getAllUniversities
- http://localhost:9000/getAllUniversities?country=united%20states&page=1&limit=2
- http://localhost:9000/getAllUniversities?name=Marywood&page=1&limit=2
- http://localhost:9000/getAllUniversities?page=1&limit=5
- http://localhost:9000/getUniversityStatistics
- The main file is app.js that imports some libraries, starts the server and injects routes to the application
- src/routes.js declares routes. In every route I am using a very basic, cache and throttling mehanism. Also every route corresponds to one controller. For example in /getAllUniversities we need the universities.getAllUniversities controler
- In src/controllers dir we have the universities and statistics controller. Universities controller is called in /getAllUniversities route and statistics controller is called in /getUniversityStatistics
- In src/test we have statistics and universities files where I have implemented the integration tests.
- In docker/api dir there is the Dockerfile.
- The external files are: gitignore(git ignores the dependencies in the file), docker-compose.yml(docker-compose), package.json(dependencies) and .babelrc(necessary if you want to use ES6 modules/features e.g import)
- I am using Mocha and I am doing integration tests in a very basic level. If you want to run these tests please type:
npm run test
-
For cache in an ideal senario I would use a distributed solution like reddis, but now I have used a npm module that caches the content in memory. That has some good and bad implications:
Good It is the fastest option available
Bad If the server goes down the data is lost
Also this is a very basic example and there is no strategy behind It. For example: What happens when data from the external api is updated?
-
Node Js and expressjs are not mulit-threaded which means that it can only process one response at a time. By using asynchronous mechanisms on your server appear multi-threaded but they are not.