#1 2023-11-26 16:53:55

igors233
Member
Registered: 2012-09-10
Posts: 241

MVC and delete requests

MVC right now is able to handle get and post (add/update) but it cannot handle delete request so I would like to propose to change TMvcRunOnRestServer.InternalRunOnRestServer

if Ctxt.Method in [mGET, mPOST] then

to

if Ctxt.Method in [mGET, mPOST, mDELETE] then

Or better yet allow for each of MVC methods to specify list of supported http methods

Offline

#2 2023-11-27 08:06:55

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: MVC and delete requests

Note that the MVC requests are expected to be regular HTTP/Web request from HTML, so are usually GET and sometimes POST (from a form).
Other methods are not supported: https://stackoverflow.com/a/73880506/458259

So my guess is that you use mDELETE because you use the MVC as a single input for both HTML/web and JSON/RPC requests.

If we add mDELETE the we should add also mPUT I guess, for consistency.
And nothing prevent you to handle any other kind of method...

I also suspect it is not enough to add mDELETE here to see it available.
Because the methods are part of the URI registration in Create.

Please try https://github.com/synopse/mORMot2/commit/82ecb05f

Offline

#3 2023-11-27 11:14:27

igors233
Member
Registered: 2012-09-10
Posts: 241

Re: MVC and delete requests

Thanks, this will be perfect.

I'm actully not serving any json to client, it's just standard get to display object record (user for example), post to add/update it and for delete I had to add a custom DeleteUser method. Now with this change it's possible to handle all general actions (get, add, update, delete) in one method which is quite neat.

I'm using htmx library with mORMot MVC and with it client application is not bound to html FORM restrictions (GET/POST only).
Html form is not even needed (it can collect input values from a standard div) and it can issue delete request as well.
It offers some really nice features so it's possible to create complex applications without much javascript on client side.
For example when new user is added/deleted by client it can automatically append/delete it to the list, so it's not necessary to refresh whole page.

Offline

#4 2023-11-27 19:48:42

mrbar2000
Member
From: Brazil
Registered: 2016-10-26
Posts: 88

Re: MVC and delete requests

ab wrote:

Note that the MVC requests are expected to be regular HTTP/Web request from HTML, so are usually GET and sometimes POST (from a form).
....
Please try https://github.com/synopse/mORMot2/commit/82ecb05f

Arnold I see your commit and I think that u put erro on your code no?

fAllowedMethods by default is [mGET, mPOST] but in some parts of code was [mGET, mHEAD]

sample

    if publishMvcInfo in fPublishOptions then
      fRestServer.ServiceMethodRegister(
before:
        MVCINFO_URI, RunOnRestServerRoot, bypass, [mGET, mHEAD]);
now:
        MVCINFO_URI, RunOnRestServerRoot, bypass, fAllowedMethods);

Offline

#5 2023-11-28 07:36:24

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: MVC and delete requests

[mGET, mHEAD] are part of fAllowedMethods so it should be fine for this /root/mvc-info page

Offline

Board footer

Powered by FluxBB