sahilsakhiya11 / carouselAssignment

0 stars 0 forks source link

Assignment Feedback #1

Open hughsoong opened 2 years ago

hughsoong commented 2 years ago

Hi Sahil,

Thank your for submitting your assignment! We had a few quick questions for you. Unfortunately you did not open a PR for us to comment on so I'll comment here instead.

  1. What changes would you make to your API design to make it "more RESTful"?
  2. If you had more time, what other refactoring or cleanup would you perform on your project?

Thanks Hugh

sahilsakhiya11 commented 2 years ago
  1. What changes would you make to your API design to make it "more RESTful"? Answer:- Mostly, nowadays JSON has become widely accepted format for sending and receiving API data instead of HTML or XML. To ensure, client interact and interprets JSON data, I should have set Content-Type = application/JSON while making a request. On the server side, I think I am good for this application because we are using express which automatically set Content-Type or we have one library called "body-parser" which helps us to set Content-Type.

One more point, on the server side, i should have named api better. instead of localhost:3000/api/sharklLists, I can name the api localhost:3000/getSharkLists. The whole point here is to make more code more readable to other developers.

This one is very important, I should have use status-code for everything, like 200 for successful data fetch and different status code for error handling too.

This one might and might not relate to this project, but system should have nesting routes so others can understand it, fo example:- posts/comments or posts/likes instead of just like /comments or /likes that will create confusion for developers that this route is for what purpose which can be either post or user or anything.

Other thing we can do to scale is we can use versioning for api like facebook or spotify. https://api.spotify.com/v1/artist/songs

Then you should set up an auto-scaling because in large project, when someone makes an api call, the API won't make the request from the first machine available — you don't know which server will get the request, because requests are bounced to different servers.

Also finally, we can go through different level of testing such as load balancing, production testing and scale testing.

  1. If you had more time, what other refactoring or cleanup would you perform on your project? Answer:- If I would have got more time, I would have researched little bit about JEST and try to write some unit test case then for the refactoring, I would have written different function for CORS policy not throwing everything in my index.js file because in large project it could have create a confusion for other devs too.

then also I would have refactor the routes code and write that function into different file.

in Frontend side, I would have add more css and make it look beautiful and as well as in code, there is a component called SingleImage, for that I should write different component for if i have imageSrc and if I dont have imgSrc then what would it be default. and store it into different component and then write the logic in singleImage component file to render it on conditional basis.