diff --git a/axios-get-trip/.env b/axios-get-trip/.env new file mode 100644 index 0000000..1c686f7 --- /dev/null +++ b/axios-get-trip/.env @@ -0,0 +1,2 @@ +NODE_ENV=development +URL=http://localhost:65534/trips?routeshortname=411 diff --git a/axios-get-trip/README.md b/axios-get-trip/README.md new file mode 100644 index 0000000..e009617 --- /dev/null +++ b/axios-get-trip/README.md @@ -0,0 +1,21 @@ +## Overview + +tbc + +## Preparation +Run the following command in your favorite terminal to install dependenies. +``` +npm i +``` +## Development setup +Run the following command in your favorite terminal if you fancy log messages for debugging. +``` +export DEBUG=$DEBUG,axios +``` +Run the following command in your favorite terminal to start the service in development mode. +``` +npm run dev +``` +## Production deployment + +tbc diff --git a/axios-get-trip/index.js b/axios-get-trip/index.js new file mode 100644 index 0000000..8b3ff2b --- /dev/null +++ b/axios-get-trip/index.js @@ -0,0 +1,35 @@ +require('dotenv').config(); +const axios = require('axios'); +const debug=require('debug')('axios'); + +const URL=process.env.URL; +debug('URL: '+URL) + +run().catch(err => { + debug('run: error') + console.log(err) +}); + +async function run() { + debug('run:...') + + //HTTP GET + let dataGet = await axios.get( + URL +//async example to process responce +// ).then(res => { +// debug('res.data: %s',res.data) +// }); + ); + + debug('data received via GET'); + debug('dataGet: %s',dataGet); + debug('dataGet.data.length: %s',dataGet.data.length); + debug('dataGet.data: %s',dataGet.data); + debug('dataGet.data[0].ageny_name: %s',dataGet.data[0].agency_name); + debug('dataGet.data[0].route_short_name: %s',dataGet.data[0].route_short_name); + debug('dataGet.data[0].agency_id: %s',dataGet.data[0].agency_id); + debug('dataGet.data[0].route_id: %s',dataGet.data[0].route_id); + debug('dataGet.data[0].service_id: %s',dataGet.data[0].service_id); + debug('dataGet.data[0].trip_id: %s',dataGet.data[0].trip_id); +} diff --git a/axios-get-trip/package.json b/axios-get-trip/package.json new file mode 100644 index 0000000..16a432f --- /dev/null +++ b/axios-get-trip/package.json @@ -0,0 +1,19 @@ +{ + "name": "axios-get-trip", + "version": "0.0.1", + "description": "", + "main": "index.js", + "scripts": { + "dev": "nodemon index.js", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Stefan Begerad", + "license": "GPL-3.0", + "devDependencies": { + "nodemon": "^2.0.7" + }, + "dependencies": { + "axios": "^0.21.1", + "dotenv": "^8.2.0" + } +}