On Tue, Feb 5, 2019 at 6:24 PM Alan Crosswell <[email protected]> wrote:
> SOAP-style remote method invocation is not RESTful. In REST, resources are > nouns and the only verbs are the HTTP methods — GET, POST, PUT, PATCH, > DELETE, etc. you’ll want to trigger actions in your views or models based > on values of the resources. See > > https://columbia-it-django-jsonapi-training.readthedocs.io/en/latest/rest.html > > > Sorry to digress a bit here, but I would disagree that remote method invocations as described here is "SOAP-style". It is not "RESTful", but by no means does it need to be anything like SOAP ( https://en.wikipedia.org/wiki/SOAP ). I think the technical term for this kind of style of "method invocation" over an API would be similar to "RPC" - or Remote-Procedure-Calls, something like https://en.wikipedia.org/wiki/JSON-RPC I think debating the pros and cons of these styles can be endless :-) - personally, I like to stick to RESTful patterns wherever possible, but for the case described here where the user just wants to pass in some parameters and get a response, and this is not tied to a data model per se, I also think forcing a RESTful approach on something that you really want to think about as "I want to pass in two parameters to a URL and get a response" often adds complexity. In this case, Hanz, personally my advice would be to start with a very simple implementation of this so you understand how the parts work, and then add framework as needed. IMHO, the "simplest" implementation would be to just use plain django, have an entry in your urls.py that points to a view function. In your view function, you simply read your GET or POST parameters from the request, perform your computations in python code, and return some JSON as response (you can use a JsonResponse object: https://docs.djangoproject.com/en/1.11/ref/request-response/#jsonresponse-objects ) . When doing something similar with Django Rest Framework, I have used the api_view decorator: https://www.django-rest-framework.org/api-guide/views/#api_view - this lets one write simple functions mapped to URLs, and reduces boilerplate you may have across these different view functions. Hopefully the examples there make sense to get you started. Hope that helps, Sanjay > On Tue, Feb 5, 2019 at 4:56 AM Jan Krňávek <[email protected]> wrote: > >> Hello everybody, >> i need to call remote method and i want to pass in parameters and to >> get response, all in json format. >> >> Suppose i have an endpoint * /api/actions* and will POST >> *{"action":"do_some_cals", >> "param1":"111","param2":"222"}* >> and will get reponse *{ "result":"333"}* >> >> There will be no model for any methods >> >> How can i do this in DRF , is there better way, how to design calling >> methods in DRF? >> >> Thank you in advance for help. >> Hanz >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django REST framework" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> For more options, visit https://groups.google.com/d/optout. >> > -- > Alan Crosswell > Associate VP & CTO > > -- > You received this message because you are subscribed to the Google Groups > "Django REST framework" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django REST framework" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
