FromQuery with FromBody fallback - asp.net-core

I have a method which accept POST and GET verbs, How can I get a property bind from the querystring if it's a GET request and from body if it's a Post Request?
Extra point if it can databind from JSON and from form encoded bodies.

Related

Can I pass in an object into a SOAP API request

The object required contains a string. When I pass in the string I receive an error. Is there a way to build up an object using XML in a SOAP request. According to my knowledge, SOAP requests have to be in XML format.

How can I access Deserialize request body object in a Filter?

We have a dropwizard micro-services, and we need to access POST request body for one of end point in a filter.
How can I access Deserialize request body object in a Filter?

How to send JSON dict in POST request?

I have this JSON dictionary:
{"userId":"363008505", "userName":"almogsh11", "friends":[{"u":"2079823612","n":"she43"},{"u":"2010211025","n":"temy63c"}]}
It contains the "friends" array. I want to send this dictionary in post http request to server.
How can I do this?
You could use the AFNetworking framework. There are a couple of methods you could use, such as JSON Parameter Encoding and URL Form Parameter Encoding.

Call a POST rest api with AddJsonBody method vs. AddObject method

I am using RestSharp to do a REST API client application. If the format of request body (pay load) for a POST Rest Api call is JSON, I would like to know when I should use RestRequest.AddJsonBody() method and when RestRequest.AddObject() method. Thank you.
To send a JSON payload, use AddJsonBody. AddObject will extract name-value pairs from the object and add them as parameters.

How to pass object to RESTful Service with GET request?

I have seen some posts in stackoverflow saying "sending list of items in the GET Method, is NOT allowed. It has to be accomplished via POST method only"
My code looks like
[OperationContract]
[WebGet(UriTemplate = "Employee/{emp}",RequestFormat=WebMessageFormat.Json)]
Employee GetEmpDetails(string emp);
and my input json object will be "{'id':1,'name':'test',....}
Is there any alternative way of achieving this issue.
Thanks
It is possible to send list of items with GET, it's just that out of the box only primitive values are supported. String values work just fine, but if you want to pass a complex object, you need to create a custom QueryStringConverter. The post at http://blogs.msdn.com/b/carlosfigueira/archive/2011/08/09/wcf-extensibility-querystringconverter.aspx explains how this can be done.
If you make your service RESTful you will most probably use HTTP PUT for Add method and HTTP POST for Update method. It is absolutely ok to pass object to these methods because objet will be part of HTTP request's body, not part of URI. URI is important for HTTP GET requests. HTTP GET requests should be only for data retrieval not for data modification.
You are mixing up HTTP GET/POST/... requests and REST GET/POST/PUT/DELETE/...
When you wanna request something RESTfully - you do a GET request. In your case I think it should look like
employee/{id}
or
employee/{name}
Please also note that usage of lowercase in the URI is preferable.
If you need multiple GET criteria, I think it could look like:
employee/id/{id}/name/{name}