简体   繁体   中英

ServiceStack routing GET requests to POST methods

I have been having an issue with Uri too long for a number of GET requests we currently have and our proposed solution is to issue post requests instead.

I'd prefer to keep my service methods using the GetXResponse Get(GetXRequest request) signature.

Is there any way to configure ServiceStack to resolve to Get methods when the request starts with 'Get'?

Customize Request Handling with X-Http-Method-Override

There's no special heuristic of Request DTO naming to Get actions, but when making the request you can use the X-Http-Method-Override in either of the HTTP Header, QueryString or FormData to specify a different verb to execute the request as.

Handle any Verb with Any() method

You can also use Any method to handle all verbs (ie inc GET/POST), eg:

GetXResponse Any(GetXRequest request) { .. }

The Any method is used as a fallback, if you also have specific verbs with the same Request DTO it will use those instead, ie:

GetXResponse Get(GetXRequest request) { .. }
GetXResponse Post(GetXRequest request) { .. }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM