1

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 3

1

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/

Sign up to request clarification or add additional context in comments.

Comments

0

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

There is already one done in Node.js, actually. But I was asked to do it in Python because the script that processes the data is made in python, and mixing it with Node.js resulted in conflicts.
Interesting. Do you know what kinds of conflicts? If you're passing around json, for instance, the sender and receiver should be able to be arbitrary.
0

For DRF: https://www.django-rest-framework.org/tutorial/quickstart/ Another viable option: Flask: https://flask.palletsprojects.com/en/1.1.x/quickstart/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.