0

I am going to make a small app but I do not know how to do it that's why I need you advice. For example, I have a api_key like that API_KEY='AdsbdmAYugjhnvcvbnRDgfcvbnb' from third party service, let's imagine this computer service group and I need to do is that when I post a computer model number (i.e XS54125) and it should return name, manufacturer, produced date, etc and I should save this details in the database but I do not know how to implement this app. Can you give me idea please? because I have never done this kind of app before. If anything is still unclear please let me know I'll try to explain in more detail. Thank you beforehand!

1
  • Create a view, that accepts the computer model and send requests to the third-party service from the view and receive the response. You can use Django models to save the response/data into your Database. Commented Dec 13, 2019 at 1:35

1 Answer 1

1

You can follow the django rest framework tutorial to create an endpoint that basically do what you need, it means:

  1. Create your project
  2. Create your api app
  3. Set in the core project your API_KEY in the settings.py file using configparser (i.e: getting the credentials from a settings.ini file)
  4. Install django rest framework
  5. Create a Computer model with all the attributes that you'll need (model number, name, manufacturer, produced date, etc)
  6. Create in your api.py file a view (inside of your api app), where you'll make a request to the third party service (i.e with requests library and if the response is in Json format, manipulate the response as you need) and in the urls.py set the endpoint url with POST method. This can be a Class that inherit from viewsets.ViewSet instead of viewsets.ModelViewSet, because you don't need to extract data from a model, but you'll be able to save the response in your Computer model. Optionally you can create a Serializer to save the data into your Computer model.
Sign up to request clarification or add additional context in comments.

2 Comments

thanks for the answer! I think requests library I should give url right? or can I give api_key? if so how can I do this can you tell plz?
Probably you'll need to do something like this: response = requests.get("<third_party_service_url>/?key=API_KEY") but you should check the third party service documentation to make sure of how to pass your key to the request

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.