What I need is simple: a piece of code that will receive a GET request, process some data, and then generate a response. I'm completely new to python web development, so I've decided to use DRF for this purpose because it seemed like the most robust solution, but every example I found online consisted of CRUDs with models and views, and I figure what I need is something more simple (since the front-end is already created). Could anyone provide an example on how to do this on DRF? (or even some other viable solution, having in mind that it needs to be robust enough to take on multiple requests at the same time in production)
3 Answers
Simple way to do thing you want is by using Django REST Framework's APIView (or @api_view decorator).
Here is an example of it in the docs: https://www.django-rest-framework.org/api-guide/views/.
Besides code on that page, you would need to register your view on appropriate route, which can be found here: https://www.django-rest-framework.org/api-guide/routers/
Comments
Django and Django REST Framework are pretty heavy products out-of-the-box.
If you want something more lightweight that can handle many incoming requests, you could create a simple Express server using Node.js. This would result in very few lines of code on your end.
Sample Node server:
var express = require('express')
var app = express()
app.get('/', (req, res) => {
res.send('hello world')
});
app.listen(8000);
2 Comments
For DRF: https://www.django-rest-framework.org/tutorial/quickstart/ Another viable option: Flask: https://flask.palletsprojects.com/en/1.1.x/quickstart/