Web Services : Parameter binding in Web APIs

It seems WebAPI have some weird idiosyncrasies:

Tips:

 

References:

 

Examples:

  1. APIs: 

public HttpResponseMessage aaa(Z z) //notice  – no [FromBody]

CURL:

curl -x 127.0.0.1:8888  -v -X POST “http://localhost:1098/api/products/aaa” -H “Content-Type: application/x-www-form-urlencoded; charset=UTF-8” –data-ascii “a=1”

curl -x 127.0.0.1:8888  -v -X POST “http://localhost:1098/api/products/aaa” -H “Content-Type: application/json; charset=UTF-8” –data-ascii “{a:12}”

curl  -x 127.0.0.1:8888  -v -X POST “http://localhost:1098/api/products” -H “Content-Type: application/json; charset=UTF-8” –data-ascii “{a:100}”


 

2. APIs

  • public string Post(PersonDTO Person)
  • public string Post([FromBody]PersonDTO Person)

 

CURL:

curl  -x 127.0.0.1:8888  -v -X POST “http://localhost:1098/api/products” -H “Content-Type: application/json; charset=UTF-8” –data-ascii “{\”FirstName\”:\”abhishek\”,\”LastName\”:\”goswami\”}”

public class PersonDTO

{

public string FirstName { get; set; }

public string LastName { get; set; }

}


 

3. APIs

  • public string Post([FromBody]string value)

 

CURL:

curl  -x 127.0.0.1:8888  -v -X POST “http://localhost:1098/api/products” -H “Content-Type: application/x-www-form-urlencoded; charset=UTF-8” –data-ascii “=Abhishek”

curl  -x 127.0.0.1:8888  -v -X POST “http://localhost:1098/api/products” -H “Content-Type: application/x-www-form-urlencoded; charset=UTF-8” –data-ascii “={\”FirstName\”:\”abhishek\”,\”LastName\”:\”goswami\”}”


 

APIs

  • public string Post(string value)

 

CURL:

curl  -x 127.0.0.1:8888  -v -X POST “http://localhost:1098/api/products/?value=ag” -H “Content-Length: 0”

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s