mccalltd / AttributeRouting

Define your routes using attributes on actions in ASP.NET MVC and Web API.
http://mccalltd.github.io/AttributeRouting/
MIT License
416 stars 89 forks source link

Post data with string content #210

Closed chrisdot closed 11 years ago

chrisdot commented 11 years ago

Hello,

First of all thanks for the good job ! Keep it up !

However, here is my problem:

It's impossible to reach a POST Uri, where the content/payload is a simple string.

[POST("Resource")]
public HttpResponseMessage CreateResource(string s)
{
}

But if I slightly modify that to (just wrapping the string in a DTO) :

[POST("Resource")]
public HttpResponseMessage CreateResource(SimpleStringDTO s)
{
}

Then it works, but is frustrating. (I'm using JSON as transport format)

Is that a bug or a feature? Christophe

mccalltd commented 11 years ago

See here for web api web host workarounds: https://github.com/mccalltd/AttributeRouting/issues/96

So this should work:

[POST("Resource"), HttpPost]
public HttpResponseMessage CreateResource([FromBody] string s)
{
    // Simple parameters are assumed to come from the URL by default. So use [FromBody]
}

or this:

[POST("Resource")]
public HttpResponseMessage PostCreateResource([FromBody] string s)
{
    // Again, Simple parameters are assumed to come from the URL by default. So use [FromBody]
}
chrisdot commented 11 years ago

OK, sorry, didn't know that [FromBody] attribute

steveoh commented 11 years ago

posting to web api is silly