AdamVig / GoCoApi

API Server for the GoCoStudent app.
https://gocostudent.adamvig.com/api
GNU General Public License v3.0
0 stars 0 forks source link

Add endpoints to interact with User data #5

Closed AdamVig closed 8 years ago

AdamVig commented 8 years ago

Missing:

AdamVig commented 8 years ago

POST /setproperty should become PUT /[user]/[propertyname] in order to be RESTful. URL names should never include verbs.

POST /createuser should become POST /[user], with the other verbs implemented as well.

AdamVig commented 8 years ago

This addition requires significant architectural changes due to the nature of the endpoint being so different from other endpoints. Most endpoints simply have a getter and a processor and either handle GET or POST requests. This makes it easy to abstract away their functionality into the Endpoint helper class and instantiate them as a batch in index.js; both measures that help reduce redundancy in the code.

These two endpoints must interact with the User model.

This does not fit in with the existing model of retrieving and processing data in the endpoint. One option to work around it is to skip using the Endpoint helper class for these two endpoints. This is difficult to implement with the existing setup, however, because all routes in the /routes folder are dynamically instantiated when the app launches.

A possible fix could be to move the endpoint instantiation into the respective endpoint definition files in /routes. index.js would either dynamically import all of the routes or simply import a file /routes/routes.js that imports all of the enabled routes (this would remove the need to use an underscore to denote disabled files and would remove some of the unnecessary "magic" from the route loading strategy).

It might make sense to create a class for each endpoint that extends the main Endpoint class and overrides methods as necessary. This would likely be a better approach than passing configuration objects around.