Parsing NewtonSoft JToken Inside WebAPI Call

One of the simplest ways to POST data from a JavaScript app (such as Angular or JQuery) to a Microsoft ASP.NET WebAPI endpoint is simply to post JSON data.  There is a lot of magic that happens to try and match up the POST data you are calling with to the WebAPI call and it often feels like there is no reason why some calls work and some don’t. My experience is that it’s easier to just process generic JSON on the WebAPI side and not worry about the shape of the data until after it arrives on your WebAPI endpoint.  Darrell Miller has a very helpful article that demystifies that data and give a very clear way to get that JSON to your WebAPI endpoint as a NewtonSoft JToken.  Darrel leaves out what to do with the JToken so I thought I’d fill … Continue Reading

Name Collisions with Asp.Net Webapi and How to Avoid

I love the simplicity of using ASP.NET WebAPI for building simple web rest services.  No special calls to create JSON, simple REST conventions implemented with the methods GET,POST,PUT and DELETE and very straight forward interfaces. The thing that annoys me is the naming convention.  In my case, I’ve create a folder /rest on my web server and I put all my WebAPI controllers there.  An example of a controller looks as follows: [crayon-58af0c0574fba306634959/]   The problems comes up when you decide you want to have a different FAQ controller for different parts of the web site.  The obvious solution is to drop the REST services into sub directories.  Unfortunately, since the class name above does not … Continue Reading

WebAPI REST Routing For AngularJS and ExtJS

As most of my readers know, I’ve done a lot of work with the JavaScript libraries made by Sencha (ExtJS and SenchaTouch).  The typical JSON sent down to the requesting web application looks like the following with both Sencha products. { "data": [ { "shirtSize": "Mens-4XL", "id": 30 }, { "shirtSize": "Mens-5XL", "id": 31 }, { "shirtSize": "Mens-6XL", "id": 32 } ], "total": 34, "success": true } Notice that it is a single JavaScript object that has a property named data which is the array we are interested in. AngularJS’s Resource api expects just the data array by default without the nice wrapping with total and status.  That is, Angular just … Continue Reading

A Minimalist WebAPI 2 Visual Studio Project

image.png

Introduction Many of us have been asking Microsoft to keep all the extra stuff out of Visual Studio 2013 projects.  For example, I don’t want JQuery in my project yet almost all project types include it.  So, here are my steps to create just WebAPI 2 and no other types that are not directly that. The Steps File / New / Project Empty Project with Just WebAPI Then, when I go into References / Manage NuGet I see just 4 packages My Solution explorer is small and if I look in my App_Start, I just have one simple file, WebApiConfig.cs which is as follows:   Project size, 29 files, 9 folders.   I’d say that’s pretty good. … Continue Reading

Follow

Get every new post delivered to your Inbox

Join other followers: