I want to create a REST API that is not bound to a model

I have found plenty of examples of using the DRF for views bound to models, but none that do just calculations or transformation. i.e. a URL to

/myapp/api/dosomething/ with either a GET method or a POST method that accepts a request, looks at the data in the request, does something and returns a response.

I created three files


class DoSomething:
def process_request(request):

requestmethod = request.method
print(‘requestmethod=’, requestmethod)

    if requestmethod == 'POST':
        mybody = str(request.body)
        print("mybody=", mybody)
        decoded_body = urllib.parse.parse_qs(mybody)

how do I create the response to return?

You probably don’t even need DRF for that. That could be a regular Django view that returns a JsonResponse. (If you’re already using DRF for the rest of your application, you could create this as an APIView class returning a DRF Response object.)

ok good to know. I guess I need an example.

There are examples of each in the referenced docs.

Ok Ken,

Thanks, I did find one in the DRF docs for function based views.