You should have installed NodeJS and npm (they come as one) in order to start the backend server.
- clone the ese2020-project-scaffolding repository
- navigate to the backend folder
cd ese2020-project-scaffolding/backend
- run
npm install
- run
npm run dev
- open your browser with the url http://localhost:3000
This part of the repository serves as a template for common problems you will face as a backend developer during your project. It is by no means complete but should give you a broad overview over the frameworks, libraries and technologies used. Please refer to the reading list for links and tutorials.
We tried to show you different approaches how your backend may be structured, however you are free to follow your own principles. Notice the differences between the UserController and e.g. TodoItemController.
- The logic is split up:
- authorizing a request is done via middleware
- logic e.g. creating/authentication is done via UserService
- The controller itself is structured as a class.
Note that the UserController
-approach is more suited for bigger architectures and for typescript applications. You may choose any aproach you wish, but make sure your code is well structured.
Here are more resources you can read:
These are links to some of the files that we have implemented/modified when developing the backend:
- Middleware
- Login:
- Registration:
- crud
- typescript config
- routing
- API construction
Some endpoints can be called in a browser, others have to be called by a REST Client. Here you can find a collection that contains all requests, which you can import into Postman. Postman is a REST Client.
-
POST
Request
{ "name": "string", "done": "boolean", "todoListId":"number" }
Response
Code: 200 Body:
{ "todoItemId": "number", "name": "string", "done": "boolean", "todoListId":"number" }
-
PUT
/:id
Request
{ "name": "string", "done": "boolean", "todoListId":"number" }
Response
Code: 200 Body:
{ "todoItemId": "number", "name": "string", "done": "boolean", "todoListId":"number" }
- DELETE
/:id
Response: Status: 200
-
POST
Request
Code: 200 Body:
{ "name":"string" }
Response
Code: 200 Body:
{ "todoListId": "number", "name":"string" }
-
PUT
/:id
Request
Code: 200 Body:
{ "name":"string" }
Response
Code: 200 Body:
{ "todoListId": "number", "name":"string" }
-
DELETE
/:id
Response: Status: 200 -
GET
Response
Code: 200 Body:
{ "todoListId": "number", "name":"string", "todoItems":"TodoItem[]" }
-
POST
/register
Request
Code: 200 Body:
{ "userName":"string", "password":"stiring" }
Response
Code: 200 Body:
{ "userId": "number", "userName":"string", "password":"string(hashed)" }
-
POST
/login
Request
Code: 200 Body:
{ "userName":"string", "password":"string" }
Response
Code: 200 || 403 Body:
{ "user": { "userId":"string", "userName":"string", "password":"stirng(hashed)" }, "token":"string" }
-
GET
Response
Code: 200 Body:
[ { "userId":"string", "userName":"string", "password":"stirng(hashed)" }, { "userId":"string", "userName":"string", "password":"stirng(hashed)" }, ... ]
-
GET
Request
Header: Authorization: Bearer +
token
Response
Code: 200 | 403 Body:
{ "message":"string" }
-
GET
Response
Code: 200 Body:
<h1>Welcome to the ESE-2020 Course</h1><span style=\"font-size:100px;\">🎉</span>