- node.js
- npm
Download the project and uncompress it.
cd BSDT_rest npm install
- The server is configured to listen in port 8000. You can modify it by changing the variable
port
inrest_server.js
file. - The server is configured to connect to database in
mongodb://localhost:27017/zips_small
. You can modify it by changing the variabledb_url
inmodel.js
file.
npm start
You can use any REST client to test the API. A test web page is also included in http://localhost:<port>/webtest.html
Examples using curl client:
curl http://localhost:8000
curl http://localhost:8000/restaurants
curl http://localhost:8000/restaurants?nombre=miRestaurante&calle=calle30
curl http://localhost:8000/restaurants/2
curl -H "Content-type:application/json" -X PUT -d '{"nombre":"Nuevo nombre"}' http://localhost:8000/restaurants/2
curl -H "Content-type:application/json" -X POST -d '{"nombre":"Mi restaurante"}' http://localhost:8000/restaurants
curl -X DELETE http://localhost:8000/restaurants/3
When using CURL in Windows, simple quotes are not accepted. For instance, to update a restaurant the next command must be used:
curl -H "Content-type:application/json" -X PUT -d "{\"nombre\":\"Nuevo nombre\"}" http://localhost:8000/restaurants/2`