Print raw api response

This commit is contained in:
Apalak Dutta 2023-06-04 21:42:42 +05:30
parent eb7667f4f5
commit 4e1c38c0ed
4 changed files with 14 additions and 6 deletions

7
backend/api/urls.py Normal file
View File

@ -0,0 +1,7 @@
from django.urls import path
from . import views
urlpatterns = [
path('',views.api_home)
]

View File

@ -1,3 +1,4 @@
from django.shortcuts import render
from django.http import JsonResponse
# Create your views here.
def api_home(request,*args,**kwargs):
return JsonResponse({"message":"This is my 1st Django api project"})

View File

@ -15,8 +15,9 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import path,include
urlpatterns = [
path('admin/', admin.site.urls),
path('api/',include('api.urls'))
]

View File

@ -1,8 +1,7 @@
import requests
endpoint = "http://127.0.0.1:8000/"
endpoint = "http://127.0.0.1:8000/api/"
get_response = requests.get(endpoint,json={"query": "Hello world"}) #HTTP Request
print(get_response.text) # print raw text response
# print(get_response.json())
print(get_response.json()['message'])
print(get_response.status_code)