need idea creating my project

Hello guys!

I hope you are all doing good.

So I am a student, and I’m supposed to create this project as an academic activity, but I want to know what would be the best practice for doing this project.

Project details:

I have access to a REST API (let's call it API # 1)

and I'm asked to develop my own django API (API # 2)based on the API # 1

so I'm just confused. normally, I have a django project with all data inside database and I create API using data using product models. but in this case, I have no database, no models. the data is coming from API # 1.

The API#2 will be doing exactly the same thing as API#1. so for example if one of the API#1 endpoints says: /api/v1/users gets us a JSON like {name: jhon, age:1}

then

this API #2 would have exactly a mirror endpoint and it is supposed to return exactly the same data so in this case API#2 would be:
/api/v2/users ===> {name: jhon, age:1}

I also have to create some sort of logger that will log the request sent to these API# 2 endpoints and whether it was success/failed with timestamp.

so how do I go about implementing this project??

thanks for your time.

As there are multiple ways of doing this, and since this is a class assignment, I’d suggest the following ideas:

  1. What have you already been exposed to, that would help you perform these individual steps?
    1. Do you know how to develop an API?
    2. Do you know how to request data from an API?
  2. Do you have any guidance at all from your instructor?
  3. Have you talked to any of your co-students to discuss how they’re approaching this?

Ken

1 Like

hello good sir, thanks for you reply.

  1. I have done number of full stack applications using Django such as creating a library management system and school management systems so I would say I have fair grip on the core concepts of Django and know how to apply them.

  2. Yes, I have created 1 RESTFUL API using Django REST framework (DFR), but in that project, we had proper database & models so I knew how to fetch data from those models, serialize them & expose them via endpoints. However, This project has no Database, no Models. we only got API to begin with and nothing else hence my confusion.

  3. Yes, I can get data from api endpoints and store them into database and show them in templates so I have no issue doing that. I can also handle POST requests using forms, & submit data back to servers via the said API

  4. Unfortunately, our Instructor is unable to help since our uni is shutdown due to covid and getting him online is not a viable option.

  5. yes, I talked to my other fellows but they are looking up to me to come up with a solution.

so far one idea that’s crossed my mind is that:

create a regular django project, and create URLs that match with the API#1 endpoints, and connect those URLs to their views and then inside views just get data in JSON from API#1 and return the same JSON data back. and have little error handling thrown it.

so what do you think? does that sound good enough for this job? let me know if there’s a better way to do this. API#1 also involves few POST requests and most of the endpoints use Auth/login as well.

Thank you so much for your time & support.

Yep, that sounds to me like a very suitable approach. (It’s how I would start.)
However, I wouldn’t be too worried about matching the endpoint names.

Ken

1 Like

hello sir,

I hope you are doing well.

so I executed the above idea and so far it’s going very well. I just have one more concern. I’m also supposed to create some sort of monitoring for these APIs such as number of times any particular url was requested whether it was success or failure. which ip address was it fetched from.

so what would be the best way to implement this tracker or monitoring for this api that I’m building?

thank you

Ok, leave aside that you are pulling this from an API. How might you track the number of times each one of your URLs have been requested?

Outside the context of Django, how can you tell whether your API fetch was successful or not?

Now, regarding the IP address - exactly which IP address are you looking to track?

The key idea here is that the core logic is the same whether you’re running these tasks from a stand-alone script or from within Django. The only difference is how they’re called.

Ken

1 Like

thanks for you detailed reply. it’s really helpful!

so I’m guessing I will need some kind of variable to keep track of how many time a certain url was called. and then maybe I should save the result in database and from there I can show records in a table.

by ip address I mean the ip address that was used to fetch the api results. I guess I could find a property for that inside REQUEST headers or something?

please let me know if I’m on the right track here

thanks for your time.

Yes, you’ll want to take a look at the HttpRequest object.

<opinion>
I know that this is primarily an academic exercise, but I am going to point out that there are many reasons and many situations where trying to track this information is meaningless. Yes, it’s ok to learn how to gather data like this. No, it’s not valid to use that data for any meaningful analysis.
</opinion>