I am creating a UI for a content production area on a company intranet. I created the middleware API in a previous project. This is my first time using RESTful methods (and I'm fairly new to Javascript and jquery in the first place)
When I call my debugging local api from the jquery.ajax the JSON object is not being passed properly on my GET method.
In the C# API
[ActionName("THING")]
[HttpGet()]
public string GetThing(object json)
{
GetData getData;
if (json == null)
return null;
else if (json is string && (json as string).StartsWith("{"))
getData = JsonConvert.DeserializeObject<GetData>(json as string);
else
return null;
ItemReturn retVAl = new ItemReturn();
[logic to use JSON]
return retVal;
in the web page
loadThings: function (thingNumber, showBool) {
showBool = (showBool === true);
$.ajax({
type: "GET",
dataType: "json",
data: '{ "GetData" : {"ThingNumber":"' + thingNumber + '","Show": ' + showBool + '}}',
url: "http://localhost:11422/api/THING/THING/GetThing",
contentType: "application/json; charset=utf-8",
success: function (result) {
[logic to display things]
}
I can hit my breakPoint in GetThing fine, have it all working, but I can't seem to figure out why the object (json) in my overload is coming in null. I know it's something in the javascript, my unit tests work fine and my JavaScript is getting me to my breakpoint in the method, I just need to overload JSON object to actually be passed in
UPDATE
It is on the api side. I changed the overload of GetThing from (object json) to ([FromUri()] object json). This fixed the immediate issue but it is currently just translating the JSON object into a blank object
++Note: I had to change my post method overload to [FromBody()] rather than [FromUri()], I am yet to update the DELETE method to see which one that uses