Sign in
Log inSign up

How do I route the POST,PUT and GET to different business logic on Django-REST framework?

Shrihari Shastry's photo
Shrihari Shastry
·Oct 19, 2016

I have started working on django-rest framework.... I selected this framework because I wanted to integrate the same api's with a mobile application(android). I had done this before with nodeJs(Express) , I used to write GET,POST,PUT and DELETE request for the same url and write business logic in it. How do i implement the same with DjangoRest....

How do I route the PUT or POST request to business logic and give a response like I do in ExpressJs

Example:

module.exports = function (router) {

    router.get('/demoEndPoint', function(req,res){
              /*business logic here
        res.send('hello world');
    });
    router.post('/demoEndPoint', function(req,res){
       /*business logic here
        res.send('hello world this Post Request');
    });
    router.put('/demoEndPoint', function(req,res){
              /*business logic here
        res.send('hello world put request');
    });
};
Hassle-free blogging platform that developers and teams love.
  • Docs by Hashnode
    New
  • Blogs
  • AI Markdown Editor
  • GraphQL APIs
  • Open source Starter-kit

© Hashnode 2024 — LinearBytes Inc.

Privacy PolicyTermsCode of Conduct