Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

nlw-education/nestjs-api-mongoose

Repository files navigation

nestjs-api-mongoose

Simple example Api Rest with Nestjs 9.x and Mongoose for the NestJS community 😻.

Installation

$ npm install

Set environment

$ cp .env.example .env

Running the app

# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod

Docker

There is a docker-compose.yml file for starting MongoDB with Docker.

$ docker-compose up

After running, you can stop the Docker container with

$ docker-compose down

Url Swagger for Api Documentation

http://127.0.0.1:3000/api/doc

Getting with Curl Customers

 $ curl -H 'content-type: application/json' -v -X GET http://127.0.0.1:3000/api/customers 
 $ curl -H 'content-type: application/json' -v -X GET http://127.0.0.1:3000/api/customers/:id 
 $ curl -H 'content-type: application/json' -v -X POST -d '{"firstName": "firstName #1", "lastName": "lastName #1", "email": "example@nest.it", "phone": "1234567890", "address": "street 1","description": "Lorem ipsum", "organizations": ":OrganizationId"}' http://127.0.0.1:3000/api/customers 
 $ curl -H 'content-type: application/json' -v -X PUT -d '{"firstName": "firstName #1", "lastName": "lastName #1", "email": "example@nest.it", "phone": "1234567890", "address": "street 1","description": "Lorem ipsum", "organizations": ":OrganizationId"}' http://127.0.0.1:3000/api/customers/:id 
 $ curl -H 'content-type: application/json' -v -X DELETE http://127.0.0.1:3000/api/customers/:id 

Getting with Curl Organizations

 $ curl -H 'content-type: application/json' -v -X GET http://127.0.0.1:3000/api/organizations 
 $ curl -H 'content-type: application/json' -v -X GET http://127.0.0.1:3000/api/organizations/:id 
 $ curl -H 'content-type: application/json' -v -X POST -d '{"name":"Foo bar", "address": "street 1", "description": "lorem ipsum"}' http://127.0.0.1:3000/api/organizations 
 $ curl -H 'content-type: application/json' -v -X PUT -d '{"name":"Foo bar", "address": "street 1", "description": "lorem ipsum"}' http://127.0.0.1:3000/api/organizations/:id 
 $ curl -H 'content-type: application/json' -v -X DELETE http://127.0.0.1:3000/api/organizations/:id

Getting Pagination using limit and offset

 $ curl -H 'content-type: application/json' -v -X GET http://127.0.0.1:3000/api/customers?limit=10
 $ curl -H 'content-type: application/json' -v -X GET http://127.0.0.1:3000/api/customers?offset=10

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /