Add the skeleton for an API app
URL handling is a hack, but it works
This commit is contained in:
parent
10005dfe02
commit
fc141c9778
8 changed files with 88 additions and 10 deletions
|
@ -17,3 +17,4 @@ djangorestframework
|
|||
django-htmx
|
||||
wagtail-metadata
|
||||
humanize
|
||||
drf-yasg
|
||||
|
|
|
@ -12,8 +12,10 @@ brotli==1.0.9 # via whitenoise
|
|||
certifi==2022.6.15 # via requests
|
||||
charset-normalizer==2.1.0 # via requests
|
||||
click==8.1.3 # via rq
|
||||
coreapi==2.3.3 # via drf-yasg
|
||||
coreschema==0.0.4 # via coreapi, drf-yasg
|
||||
deprecated==1.2.13 # via redis
|
||||
django==4.0.6 # via -r requirements/base.in, django-filter, django-htmx, django-modelcluster, django-permissionedforms, django-redis, django-rq, django-taggit, django-treebeard, djangorestframework, wagtail
|
||||
django==4.0.6 # via -r requirements/base.in, django-filter, django-htmx, django-modelcluster, django-permissionedforms, django-redis, django-rq, django-taggit, django-treebeard, djangorestframework, drf-yasg, wagtail
|
||||
django-environ==0.9.0 # via -r requirements/base.in
|
||||
django-filter==21.1 # via wagtail
|
||||
django-htmx==1.12.1 # via -r requirements/base.in
|
||||
|
@ -23,31 +25,39 @@ django-redis==5.2.0 # via -r requirements/base.in
|
|||
django-rq==2.5.1 # via -r requirements/base.in
|
||||
django-taggit==2.1.0 # via wagtail
|
||||
django-treebeard==4.5.1 # via wagtail
|
||||
djangorestframework==3.13.1 # via -r requirements/base.in, wagtail
|
||||
djangorestframework==3.13.1 # via -r requirements/base.in, drf-yasg, wagtail
|
||||
draftjs-exporter==2.1.7 # via wagtail
|
||||
drf-yasg==1.21.3 # via -r requirements/base.in
|
||||
et-xmlfile==1.1.0 # via openpyxl
|
||||
gunicorn==20.1.0 # via -r requirements/base.in
|
||||
html5lib==1.1 # via wagtail
|
||||
humanize==4.3.0 # via -r requirements/base.in
|
||||
idna==3.3 # via requests
|
||||
inflection==0.5.1 # via drf-yasg
|
||||
itypes==1.2.0 # via coreapi
|
||||
jinja2==3.1.2 # via coreschema
|
||||
l18n==2021.3 # via wagtail
|
||||
lxml==4.9.1 # via -r requirements/base.in
|
||||
markupsafe==2.1.1 # via jinja2
|
||||
more-itertools==8.13.0 # via -r requirements/base.in
|
||||
openpyxl==3.0.10 # via tablib
|
||||
packaging==21.3 # via redis
|
||||
packaging==21.3 # via drf-yasg, redis
|
||||
pillow==9.2.0 # via wagtail
|
||||
psycopg2==2.9.3 # via -r requirements/base.in
|
||||
pygments==2.13.0 # via -r requirements/base.in
|
||||
pyparsing==3.0.9 # via packaging
|
||||
pytz==2022.1 # via django-modelcluster, djangorestframework, l18n
|
||||
pytz==2022.1 # via django-modelcluster, djangorestframework, drf-yasg, l18n
|
||||
redis==4.3.4 # via django-redis, django-rq, rq
|
||||
requests==2.28.1 # via -r requirements/base.in, wagtail, wagtail-generic-chooser
|
||||
requests==2.28.1 # via -r requirements/base.in, coreapi, wagtail, wagtail-generic-chooser
|
||||
rq==1.10.1 # via django-rq
|
||||
ruamel-yaml==0.17.21 # via drf-yasg
|
||||
ruamel-yaml-clib==0.2.6 # via ruamel-yaml
|
||||
six==1.16.0 # via html5lib, l18n
|
||||
soupsieve==2.3.2.post1 # via beautifulsoup4
|
||||
sqlparse==0.4.2 # via django
|
||||
tablib[xls,xlsx]==3.2.1 # via wagtail
|
||||
telepath==0.2 # via wagtail
|
||||
uritemplate==4.1.1 # via coreapi, drf-yasg
|
||||
urllib3==1.26.11 # via requests
|
||||
wagtail==3.0.1 # via -r requirements/base.in, wagtail-draftail-snippet, wagtail-metadata
|
||||
wagtail-draftail-snippet==0.4.1 # via -r requirements/base.in
|
||||
|
|
|
@ -15,10 +15,12 @@ build==0.8.0 # via pip-tools
|
|||
certifi==2022.6.15 # via -r requirements/base.txt, requests
|
||||
charset-normalizer==2.1.0 # via -r requirements/base.txt, requests
|
||||
click==8.1.3 # via -r requirements/base.txt, black, curlylint, pip-tools, rq
|
||||
coreapi==2.3.3 # via -r requirements/base.txt, drf-yasg
|
||||
coreschema==0.0.4 # via -r requirements/base.txt, coreapi, drf-yasg
|
||||
coverage==6.4.4 # via -r requirements/dev.in
|
||||
curlylint==0.13.1 # via -r requirements/dev.in
|
||||
deprecated==1.2.13 # via -r requirements/base.txt, redis
|
||||
django==4.0.6 # via -r requirements/base.txt, django-browser-reload, django-debug-toolbar, django-filter, django-htmx, django-modelcluster, django-permissionedforms, django-redis, django-rq, django-taggit, django-treebeard, djangorestframework, wagtail
|
||||
django==4.0.6 # via -r requirements/base.txt, django-browser-reload, django-debug-toolbar, django-filter, django-htmx, django-modelcluster, django-permissionedforms, django-redis, django-rq, django-taggit, django-treebeard, djangorestframework, drf-yasg, wagtail
|
||||
django-browser-reload==1.6.0 # via -r requirements/dev.in
|
||||
django-debug-toolbar==3.5.0 # via -r requirements/dev.in
|
||||
django-environ==0.9.0 # via -r requirements/base.txt
|
||||
|
@ -30,9 +32,10 @@ django-redis==5.2.0 # via -r requirements/base.txt
|
|||
django-rq==2.5.1 # via -r requirements/base.txt
|
||||
django-taggit==2.1.0 # via -r requirements/base.txt, wagtail
|
||||
django-treebeard==4.5.1 # via -r requirements/base.txt, wagtail
|
||||
djangorestframework==3.13.1 # via -r requirements/base.txt, wagtail
|
||||
djangorestframework==3.13.1 # via -r requirements/base.txt, drf-yasg, wagtail
|
||||
djhtml==1.5.1 # via -r requirements/dev.in
|
||||
draftjs-exporter==2.1.7 # via -r requirements/base.txt, wagtail
|
||||
drf-yasg==1.21.3 # via -r requirements/base.txt
|
||||
et-xmlfile==1.1.0 # via -r requirements/base.txt, openpyxl
|
||||
factory-boy==3.2.1 # via wagtail-factories
|
||||
faker==14.1.0 # via factory-boy
|
||||
|
@ -42,15 +45,19 @@ honcho==1.1.0 # via -r requirements/dev.in
|
|||
html5lib==1.1 # via -r requirements/base.txt, wagtail
|
||||
humanize==4.3.0 # via -r requirements/base.txt
|
||||
idna==3.3 # via -r requirements/base.txt, requests
|
||||
inflection==0.5.1 # via -r requirements/base.txt, drf-yasg
|
||||
isort==5.10.1 # via -r requirements/dev.in
|
||||
itypes==1.2.0 # via -r requirements/base.txt, coreapi
|
||||
jinja2==3.1.2 # via -r requirements/base.txt, coreschema
|
||||
l18n==2021.3 # via -r requirements/base.txt, wagtail
|
||||
lxml==4.9.1 # via -r requirements/base.txt
|
||||
markupsafe==2.1.1 # via -r requirements/base.txt, jinja2
|
||||
mccabe==0.6.1 # via flake8
|
||||
more-itertools==8.13.0 # via -r requirements/base.txt
|
||||
mypy==0.971 # via -r requirements/dev.in
|
||||
mypy-extensions==0.4.3 # via black, mypy
|
||||
openpyxl==3.0.10 # via -r requirements/base.txt, tablib
|
||||
packaging==21.3 # via -r requirements/base.txt, build, redis
|
||||
packaging==21.3 # via -r requirements/base.txt, build, drf-yasg, redis
|
||||
parsy==1.1.0 # via curlylint
|
||||
pathspec==0.9.0 # via black, curlylint
|
||||
pep517==0.12.0 # via build
|
||||
|
@ -63,10 +70,12 @@ pyflakes==2.4.0 # via flake8
|
|||
pygments==2.13.0 # via -r requirements/base.txt
|
||||
pyparsing==3.0.9 # via -r requirements/base.txt, packaging
|
||||
python-dateutil==2.8.2 # via faker
|
||||
pytz==2022.1 # via -r requirements/base.txt, django-modelcluster, djangorestframework, l18n
|
||||
pytz==2022.1 # via -r requirements/base.txt, django-modelcluster, djangorestframework, drf-yasg, l18n
|
||||
redis==4.3.4 # via -r requirements/base.txt, django-redis, django-rq, rq
|
||||
requests==2.28.1 # via -r requirements/base.txt, wagtail, wagtail-generic-chooser
|
||||
requests==2.28.1 # via -r requirements/base.txt, coreapi, wagtail, wagtail-generic-chooser
|
||||
rq==1.10.1 # via -r requirements/base.txt, django-rq
|
||||
ruamel-yaml==0.17.21 # via -r requirements/base.txt, drf-yasg
|
||||
ruamel-yaml-clib==0.2.6 # via -r requirements/base.txt, ruamel-yaml
|
||||
six==1.16.0 # via -r requirements/base.txt, html5lib, l18n, python-dateutil
|
||||
soupsieve==2.3.2.post1 # via -r requirements/base.txt, beautifulsoup4
|
||||
sqlparse==0.4.2 # via -r requirements/base.txt, django, django-debug-toolbar
|
||||
|
@ -77,6 +86,7 @@ tomli==2.0.1 # via black, build, mypy, pep517
|
|||
types-requests==2.28.5 # via -r requirements/dev.in
|
||||
types-urllib3==1.26.17 # via types-requests
|
||||
typing-extensions==4.3.0 # via mypy
|
||||
uritemplate==4.1.1 # via -r requirements/base.txt, coreapi, drf-yasg
|
||||
urllib3==1.26.11 # via -r requirements/base.txt, requests
|
||||
wagtail==3.0.1 # via -r requirements/base.txt, wagtail-draftail-snippet, wagtail-factories, wagtail-metadata
|
||||
wagtail-draftail-snippet==0.4.1 # via -r requirements/base.txt
|
||||
|
|
0
website/api/__init__.py
Normal file
0
website/api/__init__.py
Normal file
40
website/api/urls.py
Normal file
40
website/api/urls.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
from django.urls import include, path, re_path
|
||||
from drf_yasg import openapi
|
||||
from drf_yasg.views import get_schema_view
|
||||
from rest_framework import permissions
|
||||
|
||||
from . import views
|
||||
|
||||
app_name = "api"
|
||||
|
||||
api_urlpatterns = [path("ping", views.PingAPIView.as_view(), name="ping")]
|
||||
|
||||
schema_view = get_schema_view(
|
||||
openapi.Info(
|
||||
title="Website API",
|
||||
default_version="v1",
|
||||
description="Random API endpoints for cool things",
|
||||
),
|
||||
public=True,
|
||||
permission_classes=[permissions.AllowAny],
|
||||
patterns=[
|
||||
# HACK: Ensure the created URLs are fully-formed
|
||||
path("api/", include(api_urlpatterns))
|
||||
],
|
||||
)
|
||||
|
||||
urlpatterns = [
|
||||
re_path(
|
||||
r"^swagger(?P<format>\.json|\.yaml)$",
|
||||
schema_view.without_ui(cache_timeout=0),
|
||||
name="schema-json",
|
||||
),
|
||||
re_path(
|
||||
r"^swagger/$",
|
||||
schema_view.with_ui("swagger", cache_timeout=0),
|
||||
name="schema-swagger-ui",
|
||||
),
|
||||
re_path(
|
||||
r"^redoc/$", schema_view.with_ui("redoc", cache_timeout=0), name="schema-redoc"
|
||||
),
|
||||
] + api_urlpatterns
|
12
website/api/views.py
Normal file
12
website/api/views.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
from django.http.request import HttpRequest
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
|
||||
|
||||
class PingAPIView(APIView):
|
||||
"""
|
||||
PONGs
|
||||
"""
|
||||
|
||||
def get(self, request: HttpRequest) -> Response:
|
||||
return Response("PONG")
|
|
@ -59,6 +59,7 @@ INSTALLED_APPS = [
|
|||
"generic_chooser",
|
||||
"wagtail_draftail_snippet",
|
||||
"django_rq",
|
||||
"drf_yasg",
|
||||
"django.contrib.auth",
|
||||
"django.contrib.contenttypes",
|
||||
"django.contrib.sessions",
|
||||
|
@ -207,3 +208,6 @@ if DEBUG:
|
|||
|
||||
# Add Wagtail styleguide
|
||||
INSTALLED_APPS.append("wagtail.contrib.styleguide")
|
||||
|
||||
|
||||
SWAGGER_SETTINGS = {"USE_SESSION_AUTH": False, "SECURITY_DEFINITIONS": {}}
|
||||
|
|
|
@ -27,6 +27,7 @@ urlpatterns = [
|
|||
path("404/", page_not_found, name="404"),
|
||||
path("feed/", AllPagesFeed(), name="feed"),
|
||||
path("", include("website.legacy.urls")),
|
||||
path("api/", include("website.api.urls")),
|
||||
]
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue