Skip to content

pedrorobsonleao/simpleHttpDBApi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simpleHttpServerMongoCrudJs

Simple Http Server and MongoDB Rest Crud - Node.js

glossário

$ tree
.
├── LICENSE                       # A GPL 3.0 License
├── README.md                     # This File
├── package.json
└── server
    ├── bin
    │   └── httpd                 # httpd server starter
    ├── etc
    │   └── config.js             # a configuration file
    ├── lib
    │   ├── mongo.js              # mongodb pool implementation
    │   ├── server.js             # server library implementation
    │   └── string.js             # aux string normalize library 
    └── modules
        └── mongocrud.js          # CRUD implementation to mongodb

5 directories, 9 files

The code is a HTTPD configurable server sample with a CRUD MongoDB api REST implemented.

Use this code to learning about NodeJs, HTTP server, MongoDB, RestFul api services.

This code is write to run in HEROKU environment.

To run in your machine or c9.io change the file config.js or set the variables:

$ export MONGODB_URI=mongodb://localhost:27017/test
$ export PORT=9090
$ yarn install
$ yarn start

create - (method POST)

/collection

sample

$ curl -X POST -d server=httpd -d db=mongodb http://localhost:9090/crud1

Save in database a document posted in BODY.

read - (method GET)

/collection

sample

$ curl -X GET http://localhost:9090/crud

Read a object paginated from database.

{
    "page":2,
    "pages":10,
    "total":100,
    "prev":"http://localhost:9090/crud?page=1",
    "next":"http://localhost:9090/crud?page=3",
    "itens":[
        ...
    ]
}
/collection/:_id

sample

$ curl -X GET http://localhost:9090/crud1/59471588594c2159d047661f

Read a one object from database by ID.

update - (method PUT)

/collection/:_id

sample

$ curl -X PUT -d api=rest http://localhost:9090/crud1/59471588594c2159d047661f

Update a object in database.

delete - (method DELETE)

/collection/:_id

sample

$ curl -X DELETE http://localhost:9090/crud1/59471588594c2159d047661

Delete a object from database.

About

Simple Http Server and MongoDB Rest Crud - Node.js

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors