Skip to content

Latest commit

 

History

History
79 lines (48 loc) · 2.05 KB

rest-framework.rst

File metadata and controls

79 lines (48 loc) · 2.05 KB

Django Rest Framework

This package comes with viewsets and serializers compatible with Django Rest Framework.

To use the them in your API, simply register the viewsets in a router like so:

from rest_framework import routers
from prompt_responses.viewsets import PromptViewSet, PromptSetViewSet

router = routers.DefaultRouter()
router.register(r'prompts', PromptViewSet)
router.register(r'prompt-sets', PromptSetViewSet)

urlpatterns = [
    url(r'^api/', include(router.urls))
]

This offers read-only API endpoints for prompts and prompt sets and one writable endpoint to create responses.

The API endpoints are hyperlinked together, i.e. they return URLs to other resources. It is recommended to follow these links instead of constructing your own URLs.

Note that by default all the read-only endpoints are public. Only the create-response endpoint requires authentication.

Prompt API

Get a list of all prompts:

GET api/prompts/

Get details about a prompt:

GET api/prompts/<prompt_id>/

Get an instance of a prompt:

GET api/prompts/<prompt_id>/instantiate/

Get an instance of a prompt within the context of a prompt set:

GET api/prompts/<prompt_id>/instantiate/<prompt_set_name>/

When instantiating prompts like this, the instance will contain a next_prompt_instance field that links to the next prompt in the set (or null for the last prompt).

Create Response API

Save a response for a prompt:

POST api/prompts/<prompt_id>/create-response/

This endpoint expects the following data:

TODO

PromptSet API

Get a list of all prompt sets:

GET api/prompt-sets/

Get details about a prompt set:

GET api/prompt-sets/<prompt_set_name>/

Traversing an ordered list of prompts

When you use prompt sets, you can follow the links returned in the responses to traverse the list of prompts. Both PromptSet and Prompt API responses will contain a next_prompt_instance URL.