Giter VIP home page Giter VIP logo

comuni-service's Introduction

Build Status Coverage Status

Comuni Service

This is an api that expose Italian municipality information. It takes data from istat website and expose it to the client in json format

Here are URL where it takes the data:

How it works

Install dependencies

npm install

env variable

you need to use these env variables. Feel free to change it in order to strict your envoirement rules.

NODE_ENV=development
HOST=0.0.0.0
PORT=3000
COMUNI_JSON_FILE=comuni.json

The project has on its dependencies dotenv, so you can use the .env.example file provided (remove the .example notation) or use it in CLI using export command or whatever you like.

Update comuni data

npm run update:comuni

Start server

npm run start

Routes

Comuni

Returns json data about all Italian comuni.

  • URL

    /comuni

  • Method:

    GET

  • Data Params

    • provincia=[string]
    • regione=[string]
  • Example

curl -X GET http://127.0.0.1:3000/comuni?provincia=bs -H 'Content-Type: application/json'

Comune

Returns json data about a single Italian comune.

  • URL

    /comuni/:comune

  • Method:

    GET

  • Url Params

    • comune=[string]
  • Example

curl -X GET http://127.0.0.1:3000/comuni/brescia -H 'Content-Type: application/json'

Regioni

Returns an array of Italian regioni

  • URL

    /regioni

  • Method:

    GET

  • Example

curl -X GET http://127.0.0.1:3000/regioni -H 'Content-Type: application/json'

Province

Returns an array of Italian province

  • URL

    /province

  • Method:

    GET

  • Example

curl -X GET http://127.0.0.1:3000/province -H 'Content-Type: application/json'

Docker

build container

docker build --build-arg PORT=3000 -t comuni-service .

run container

docker run -d -p 3000:3000 comuni-service --env-file ./.env

update comuni in container

docker exec -i container_name node /app/bin/updateComuni.js

Public endpoint

http://comuni-service.webabile.it/

comuni-service's People

Contributors

juanramino avatar lucapalomba avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

lucapalomba

comuni-service's Issues

Add foreign states

Add foreign states data:

  • Name
  • Italian province ('EE')
  • Italian code

It could be nice to find a public URL that show this data and update it ISTAT do with Italian municipality.

For now I find this data (attached)
foreign.json.txt

Restart after Update strategy

I see that the command for updating data is:
cd /app/ && npm run update:comuni && pm2 restart comuni-service

So, each time the comuni was updated, the service stopped and restart.
In my opnion this is not the best way to do this, cause all the service flat out and reopen in memory all the Db, each time. Image this in a polling service. And if an error happen and the new file wasn't created? You cannot rollback or restart the service.

So i was thinking about using the --watch option for pm2.
Think about the procedure with this parameter. The comuni.json was update (my last PR) only if there is a true changing event. And the use of the watch parameter can drop the major part of useless "stop and start" procedure.

The problem is:
In this scenario, you should have a static name for the Json, cause the watch parameter do the best watching for a file or a folder. So i propose to change the Env variable name for the file JSON in a static one (comuni.json) for example, in order to accomplish all the strategies i wrote before.

What about?

Not a real test

I see the comuniUpdater.js tests but, in my opinion these are not real tests. There are a few considerationts around this:

  • Test should be consistent. This is not true at the moment, cause if you check the updater flow, can pass or not in base of the ISTAT site reachable condition.
  • Test should be replicable. Is not true too cause jsonFile is conditional so you cannot run al the tests in the same moment.

What's your opinion?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.