Skip to content

Latest commit

 

History

History
311 lines (249 loc) · 5.56 KB

File metadata and controls

311 lines (249 loc) · 5.56 KB

ESE2020 Scaffolding Backend

Prerequisite

You should have installed NodeJS and npm (they come as one) in order to start the backend server.

Start

  • 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

About

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.

  1. The logic is split up:
    • authorizing a request is done via middleware
    • logic e.g. creating/authentication is done via UserService
  2. 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:

Quick Links

These are links to some of the files that we have implemented/modified when developing the backend:

Endpoints

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.

/todoitem

  • 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

/todolist

  • 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[]"
     }

/user

  • 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)"
     	},
     	...
     ]
    

/secured

  • 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;\">&#127881;</span>