1👍
✅
Say you have a FBV mapped to an URL in django like this:
url: /api/animals/<str:key>
@add_decorators_as_needed
def animals_view(request, key=None):
data = requests.get(f'{API_URL}/{key}?api_key={API_KEY}') # grab data from ext provider
json_data = ... # convert to json or do other manipulations
return json_data # return data to the frontend
Then in the frontend, your Angular app, you can execute a get request to this /api/animals/cow
url of your django app and retrieve the data for a cow from the external provider without exposing your API_KEY.
So the flow would be like this:
Angular requests data from Django, Django gets that data from the external provider, does some data processing if required and then returns that data to Angular. You do not have to store anything in the database (but you can of course do it or for example log things, it’s optional).
👤dacx
Source:stackexchange.com