Nerd
Nerd

Reputation: 275

getting data from api_key in django restframework

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!

Upvotes: 0

Views: 208

Answers (1)

Manuel Carrero
Manuel Carrero

Reputation: 637

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.

Upvotes: 1

Related Questions