Skip to content

Latest commit

 

History

History
262 lines (170 loc) · 3.57 KB

13_Create_Read_Update_Destroy_Server_Setup.md

File metadata and controls

262 lines (170 loc) · 3.57 KB

[Stephen Grider] Microservices with Node JS and React [ENG, 2020]

13. Create-Read-Update-Destroy Server Setup


01. Ticketing Service Overview


02. Project Setup

$ cd app
$ mkdir tickets

copy some files from auth project

$ npm install

03. Running the Ticket Service

$ skaffold dev

04. Mongo Connection URI


05. Quick Auth Update


06. Test-First Approach

$ cd tickets
$ npm run test

07. Creating the Router


08. Adding Auth Protection


09. Faking Authentication During Tests


09. Faking Authentication During Tests


10. Building a Session


11. Testing Request Validation


12. Validating Title and Price


13. Reminder on Mongoose with TypeScript


Application


14. Defining the Ticket Model


15. Creation via Route Handler


16. Testing Show Routes


17. Unexpected Failure!


18. What's that Error!


19. Better Error Logging

$ cd common
$ npm run publish

$ cd tickets
$ npm update @grider-ms-tickets/common

19. Better Error Logging


20. Complete Index Route Implementation


21. Ticket Updating


22. Handling Updates


23. Permission Checking


23. Permission Checking


24. Final Update Changes


25. Manual Testing


// SIGN UP
$ curl \
--insecure \
--cookie-jar /tmp/cookies.txt \
--data '{"email":"[email protected]", "password":"123456789"}' \
--header "Content-Type: application/json" \
--request POST https://ticketing.dev/api/users/signup \
| python -m json.tool

// SIGN IN
$ curl \
--data '{"email":"[email protected]", "password":"123456789"}' \
--header "Content-Type: application/json" \
--request POST http://ticketing.dev/api/users/signin \
| python -m json.tool

// GET CURRENT USER
$ curl \
--insecure \
--cookie /tmp/cookies.txt \
--header "Content-Type: application/json" \
--request GET https://ticketing.dev/api/users/currentuser \
| python -m json.tool

// CREATE TICKET
$ curl \
--insecure \
--cookie /tmp/cookies.txt \
--data '{"title":"concert", "price":10}' \
--header "Content-Type: application/json" \
--request POST https://ticketing.dev/api/tickets \
| python -m json.tool

response:

{
    "__v": 0,
    "id": "5ebaa8a74cea0900186b7ec8",
    "price": 10,
    "title": "concert",
    "userId": "5ebaa6a3fc342b0023ded8a4"
}

// GET TICKET
$ curl \
--insecure \
--header "Content-Type: application/json" \
--request GET https://ticketing.dev/api/tickets/5ebaa8a74cea0900186b7ec8 \
| python -m json.tool

response:

{
    "__v": 0,
    "id": "5ebaa8a74cea0900186b7ec8",
    "price": 10,
    "title": "concert",
    "userId": "5ebaa6a3fc342b0023ded8a4"
}

// GET ALL TICKET
$ curl \
--insecure \
--header "Content-Type: application/json" \
--request GET https://ticketing.dev/api/tickets/ \
| python -m json.tool

// UPDATE TICKET
$ curl \
--insecure \
--cookie /tmp/cookies.txt \
--data '{"title":"new concert", "price":100}' \
--header "Content-Type: application/json" \
--request PUT https://ticketing.dev/api/tickets/5ebaa8a74cea0900186b7ec8 \
| python -m json.tool



Marley

Any questions in english: Telegram Chat
Любые вопросы на русском: Телеграм чат