Code Review : I was given a task , i need your comment on my approach

I was given a task to create an endpoint with the following response and i used my preferd stack jango ,

Endpoint: [GET] <>/api/hello?visitor_name="Mark"


{ "client_ip": "", // The IP address of the requester "location": "New York" // The city of the requester "greeting": "Hello, Mark!, the temperature is 11 degrees Celcius in New York" }

this is my approach Here

I Need Your comment

Hi mate, the API seems to be working and enough for a simple task.
Beside, I would like to give you some reviews about best practices:

  1. Do not put logic in views. Views should be simple
  2. Use Python open-source library for IP check, city, weather. You don’t need to code by yourself.
  3. Move the logic to library directory (libs), do not add them all to the views.
  4. Write unittest to add more value to your solution.
  5. Add coding style check, ex: flake8, black.
  6. Name your serializer better, ex: VisitorSerializer
  7. You can also move the logic to serializer so your view code will be like:
serializer = VisitorName(data=request.GET)
if not serializer.is_valid():
    return Response(serializer.errors)
return Response(
1 Like

Thanks so much …
ill go through the points you highlighted and implement them,
then get back to you for another review …

1 Like

Note: There is one item I suggest you ignore.

Don’t bother doing this for such a small project. There’s no value created by adding extra unnecessary files. (Python is not Java, PHP, C++, etc. Don’t just follow patterns establish in frameworks created in other languages without understanding why those patterns evolved there.)

Yes, a project can grow large enough such that there might be some value to doing that under certain circumstances. But for a prototype / test case like this, I would consider it a negative.

1 Like

Thanks Ken, i appreciate your feedback