|
| 1 | +# NASA NEO (Near Earth Objects) API |
| 2 | + |
| 3 | +This API is built on top of official [NASA NEO API](https://api.nasa.gov/neo/?api_key=N7LkblDsc5aen05FJqBQ8wU4qSdmsftwJagVK7UD) allowing custom queries about hazardous asteroids. |
| 4 | + |
| 5 | +## Example |
| 6 | + |
| 7 | +### GET all possible hazardous asteroids |
| 8 | + |
| 9 | +```shell |
| 10 | +curl --request GET \ |
| 11 | + --url http://localhost:3000/neo/hazardous \ |
| 12 | + --header 'content-type: application/json' \ |
| 13 | +``` |
| 14 | + |
| 15 | +response: |
| 16 | + |
| 17 | +```json |
| 18 | +[ |
| 19 | + { |
| 20 | + "_id": "59bafeb5fea87d001c3c011e", |
| 21 | + "__v": 0, |
| 22 | + "date": "2017-09-14T00:00:00.000Z", |
| 23 | + "reference": "2088254", |
| 24 | + "speed": 59540.7422645489, |
| 25 | + "is_hazardous": true |
| 26 | + }, |
| 27 | + { |
| 28 | + "_id": "59bafeb5fea87d001c3c011f", |
| 29 | + "__v": 0, |
| 30 | + "date": "2017-09-14T00:00:00.000Z", |
| 31 | + "reference": "2310560", |
| 32 | + "speed": 77331.2021001263, |
| 33 | + "is_hazardous": true |
| 34 | + }, |
| 35 | + { |
| 36 | + "_id": "59bafeb5fea87d001c3c0135", |
| 37 | + "__v": 0, |
| 38 | + "date": "2017-09-11T00:00:00.000Z", |
| 39 | + "reference": "3507718", |
| 40 | + "speed": 43820.0818093472, |
| 41 | + "is_hazardous": true |
| 42 | + } |
| 43 | +] |
| 44 | +``` |
| 45 | + |
| 46 | +## Running the application |
| 47 | + |
| 48 | +The application is built with Node.js and already has all environment configured with docker. To start the application you will need `docker` and `docker-compose` installed on the machine. Having that you may run: |
| 49 | + |
| 50 | +```shell |
| 51 | +docker-compose up |
| 52 | +``` |
| 53 | + |
| 54 | +And then the application and database will be started: |
| 55 | + |
| 56 | +```shell |
| 57 | +Starting nodenasa_mongodb_1 ... |
| 58 | +Starting nodenasa_mongodb_1 ... done |
| 59 | +Starting nodenasa_app_1 ... |
| 60 | +Starting nodenasa_app_1 ... done |
| 61 | +``` |
| 62 | + |
| 63 | +The application will be avaible on *PORT 3000* by default, but it's configurable via `docker-compose.yml` file as an environment variable. |
| 64 | + |
| 65 | +### Running the application in development mode |
| 66 | + |
| 67 | +Sometimes you would like to run the application in development mode. This project already has a prepared enviroment for that, you have to run: |
| 68 | + |
| 69 | +```shell |
| 70 | +docker-compose -f docker-compose.development.yml up |
| 71 | +``` |
| 72 | + |
| 73 | +This docker compose file will start the application using [`nodemon`](https://github.com/remy/nodemon) and will share the local application code with the container. Any change on the hosts code will restart the application (whitout restarting the container because nodemon is taking care of that). |
| 74 | + |
| 75 | +### Running the tests |
| 76 | + |
| 77 | +To run the tests using docker you just have to run the following command: |
| 78 | + |
| 79 | +```shell |
| 80 | +docker-compose -f docker-compose.test.yml up |
| 81 | +``` |
| 82 | + |
| 83 | +And then all tests will be ran and the status exit code will be 0 or 1 that means true or false. |
| 84 | + |
| 85 | + |
| 86 | +## Routes |
| 87 | + |
| 88 | +This application includes many routes ralated to NEO operations that are: |
| 89 | + |
| 90 | +### List all NEO Hazardous asteroids |
| 91 | + |
| 92 | +The following request will filter all possible hazardous asteroids that includes the flag `is_hazardous: true`. |
| 93 | + |
| 94 | +```curl |
| 95 | +curl --request GET \ |
| 96 | + --url http://localhost:3000/neo/hazardous \ |
| 97 | +``` |
| 98 | + |
| 99 | +### List the fastest asteroid |
| 100 | + |
| 101 | +This route will return the fastest asteroid based on its `speed` |
| 102 | + |
| 103 | +```curl |
| 104 | +curl --request GET \ |
| 105 | + --url http://localhost:3000/neo/fastest \ |
| 106 | + --header 'content-type: application/json' \ |
| 107 | +``` |
| 108 | + |
| 109 | +The response will be something like: |
| 110 | + |
| 111 | +```json |
| 112 | +[ |
| 113 | + { |
| 114 | + "_id": "59bb010df4d9b7001c68a1d9", |
| 115 | + "__v": 0, |
| 116 | + "date": "2017-09-14T00:00:00.000Z", |
| 117 | + "reference": "3685816", |
| 118 | + "speed": 124405.6335547075, |
| 119 | + "is_hazardous": false |
| 120 | + } |
| 121 | +] |
| 122 | +``` |
| 123 | + |
| 124 | +Also is possible to filter only hazardous asteroids passing the parameter `hazardous=true` as the example below: |
| 125 | + |
| 126 | +```curl |
| 127 | +curl --request GET \ |
| 128 | + --url 'http://localhost:3000/neo/fastest?hazardous=true' \ |
| 129 | + --header 'content-type: application/json' \ |
| 130 | +``` |
| 131 | + |
| 132 | +### List the year with most asteroids |
| 133 | + |
| 134 | +This route will return the year with most asteroids: |
| 135 | + |
| 136 | +```curl |
| 137 | +curl --request GET \ |
| 138 | + --url http://localhost:3000/neo/best-year \ |
| 139 | + --header 'content-type: application/json' \ |
| 140 | +``` |
| 141 | + |
| 142 | +This also suports `hazards=true|false` filter parameter. |
| 143 | + |
| 144 | +### List the month with most asteroids |
| 145 | + |
| 146 | +This route will return the month with most asteroids |
| 147 | + |
| 148 | +```curl |
| 149 | +curl --request GET \ |
| 150 | + --url http://localhost:3000/neo/best-month \ |
| 151 | + --header 'content-type: application/json' \ |
| 152 | +``` |
| 153 | + |
| 154 | +This also supports `hazards=true|false` filter parameter. |
| 155 | + |
| 156 | + |
| 157 | +## Populating the local database |
| 158 | + |
| 159 | +By default `every time` the application is started it fetches the NASA api and stores the data from NEOs from the last **3 days**. It's configurable via enviroment variable: `FETCH_DAYS_FROM_NOW` (NASA app is limited to 7 days). |
| 160 | + |
0 commit comments