With state management implemented on the client side, it’s time to design the server side.

All of the storage used to be a local browser cache, which was accidentally cleaned up and gone. It’s better to put it on the server.

This needs to deal with user registration, login, session issues. However, it is not a core function at this stage, and only a single user can be set up in the development stage.

This section describes the API design of major functions. The point is to plan the API with a uniform structure to make it more efficient for actual coding later.

Referring to the previous project of hugging a classmate, we designed the request URL, data format and return value of several major apis.

A few examples:

Task

Create a task

POST /task
Copy the code

Parameters

{
    "name": "Fruit"."desc": "Eat fruit every day"."type": "task"."isOneTime": false."score": 2."maxTimes": 3
}
Copy the code

When isOneTime is true, maxTimes will be set to 1.

Response

Status: 201 Created

{
    "taskId": 1
}
Copy the code

Delete a task

DELETE /projects/:projectId
Copy the code

Response

Status: 200 OK

{}
Copy the code

Log

Create a log

POST /projects/:projectId/logs
Copy the code

Parameters

{
    "userId": 1."taskId": 1
}
Copy the code

Response

Status: 201 Created

{
    "projectId": 1
}
Copy the code

With a detailed document in place, it is possible to quickly implement as planned later in the development phase.

In subsequent articles, database design, server architecture, and API development tests will be documented.

Series of articles:

React + MobX + Electron + node. js + MongoDB full stack project development practice (zero) Introduction

React + MobX + Electron + node.js + MongoDB

Allow decorators

React + MobX + Electron + node. js + MongoDB