Browse Source

Print raw api response

master
Apalak Dutta 1 year ago
parent
commit
4e1c38c0ed
4 changed files with 14 additions and 6 deletions
  1. +7
    -0
      backend/api/urls.py
  2. +3
    -2
      backend/api/views.py
  3. +2
    -1
      backend/cfehome/urls.py
  4. +2
    -3
      py_client/basic.py

+ 7
- 0
backend/api/urls.py View File

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

+ 3
- 2
backend/api/views.py 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"})

+ 2
- 1
backend/cfehome/urls.py 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'))
]

+ 2
- 3
py_client/basic.py 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)

Loading…
Cancel
Save