Scott Hanselman

Installing HTTPIE (HTTP for Humans) on Windows - Great for ASP.NET Web API and RESTful JSON services

August 17, '12 Comments [38] Posted in ASP.NET | Open Source | Web Services
Sponsored By

Recently in on a post on the RESTful ASP.NET Web API framework I used curl to post JSON to an HTTP endpoint:

curl -X POST -H "Content-Type: application/json" -d "{ Name: 'Scott Guthrie', Age: 67}"

Curl is lovely and should be in your c:\utils folder and more importantly in your PATH. I have a UTILS folder in my Dropbox and in the PATH on all my machines. Whenever I find a useful no-install utility I put it in there.

Curl is great but it's still confusing enough to me that I don't use it enough. It's slightly obscure command-line switches are keeping me from using it on a regular basis.

For HTTP work there is a better utility called HTTPie at http://httpie.org. (It has nothing to do with IE (Internet Explorer)). For Mac and Linux folks who use Python all the time, it's easy to install, you just

pip install -U httpie

For Windows folks who don't use Python it's a little harder to install, but it's worth it and I recommend you take a moment and set it up. You'll wonder how you lived without it.

Installation of HTTPIE

First, go download Python. I got the x86 version of Python 3.2.3 cause it was the latest and I didn't think I needed the x64 one.

I then added c:\python32 and c:\python32\scripts to my path. I do this by hitting WinKey+Break, then Advanced, then Environment.

Add Python and Python/Scripts to your PATH

Second, download CURL. Yes, I realize the irony, but it's still a VERY useful tool. I downloaded the 7.27 binary SSL Win32 version, unblocked it, unzipped it and put it in C:\UTILS so it was automatically in my PATH.

Third, run this from an Administrator command prompt. Note again that it needs both curl.exe and python.exe in the PATH to run as it is. This should run without incident.

curl http://python-distribute.org/distribute_setup.py | python

Then run

curl -k https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python

This should end with "successfully installed pip."

Pip is a Python package manager.

Finally, run

pip install -U https://github.com/jkbr/httpie/tarball/master

I'm recommending you install the development edge build of HTTPie rather than just "pip install httpie" as the developer is actively fixing Windows issues and just recently helped me with one.

So, to sum up what you need to run, in four lines, assuming curl.exe, python.exe and python scripts are all in your PATH.

curl http://python-distribute.org/distribute_setup.py | python
curl -k https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python
curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python
pip install -U https://github.com/jkbr/httpie/tarball/master

Running HTTPie

You'll know it works if you can run "http" from the command line and get this output:

C:\Users\scottha\Desktop> http
usage: http-script.py [--help] [--version] [--json | --form] [--output FILE]
[--pretty | --colors | --format | --ugly]
[--print OUTPUT_OPTIONS | --verbose | --headers | --body]
[--style STYLE] [--stream] [--check-status]
[--auth USER:PASS] [--auth-type {basic,digest}]
[--verify VERIFY] [--proxy PROXY] [--allow-redirects]
[--timeout SECONDS] [--traceback] [--debug]
[METHOD] URL [ITEM [ITEM ...]]
http-script.py: error: too few arguments

Here's where the fun happens. The syntax is VERY intuitive. Here I post some JSON to an endpoint that will echo it back.

C:\> http POST http://localhost:50231/api/Contact name=scott age:=100
HTTP/1.1 200 OK
Content-Length: 26
Content-Type: application/json; charset=utf-8
Date: Fri, 17 Aug 2012 21:59:51 GMT
Server: Microsoft-HTTPAPI/2.0

{
"age": 100,
"name": "scott"
}

It's just like using HTTP itself, except from the command line. The best part is that it will take name=value for strings and name:=value for non-strings and turn it into JSON!

HTTPie supports any HTTP Verb, FORM data, raw JSON, and lots of other features. Here's another example:

C:\>http PUT api.example.com/person/1 name=John age:=29 married:=false hobbies:='["http", "pies"]'
PUT /person/1 HTTP/1.1
Accept: application/json
Content-Type: application/json; charset=utf-8
Host: api.example.com
User-Agent: HTTPie/0.2.7dev

{
"age": 29,
"hobbies": [
"http",
"pies"
],
"married": false,
"name": "John"
}

There's lots more examples here https://github.com/jkbr/httpie/ and I encourage you to check it out. I'll leave you with a lovely PowerShell screenshot showing that HTTPie also does syntax highlighting at the command line!

HTTPie is HTTP for Humans and Syntax Highlights as well

Awesome. Expect to see this tool in all my Web API and JSON demos. Go get it and star it at GitHub.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Visual Studio 2012 and .NET Framework 4.5 is RELEASED - Here's 5 minute videos to get you up to speed quick

August 15, '12 Comments [92] Posted in ASP.NET | ASP.NET Ajax | ASP.NET Dynamic Data | ASP.NET MVC | Open Source | SignalR | VS2012
Sponsored By

Jason Zander announced today that Visual Studio 2012 and .NET Framework 4.5 is RELEASED to web. The .NET Web Tools Team (the team I'm on) has coverage on their blog as well. I thought I'd showcase some Tiny Happy Features that the team worked on just because it made life better. Some are large some are small, but all are tiny happy features.

I'll continue for a few more Tiny Happy Features over the next few weeks but this last week I took some time and recorded 13 (ya, thirteen, oy) short videos to show you guys these features in action. These are SHORT videos that are at most 4 to 6 minutes. It's hard to watch 60 to 90 minute screencast so I did these little one-take quick shots so you could watch them at lunch.

If you watch all these videos it will take you less than an hour and you'll have a good practical idea of what's new in Web Development and Tools with Visual Studio 2012. This is by no means exhaustive, but it's a lot.

The other concept that's worth pointing out is One ASP.NET. We've pulled the Web Tooling and Templates out into extensions in Visual Studio 2012. This means we can update Web Tools without updating all of Visual Studio. I talked about this in the One ASP.NET keynote at aspConf. We'll be updating the tools - not in major scary ways - but in useful and important ways that make front end web development easier. We'll look at small updates either quarterly or maybe semi-annually so when a new technique comes out you don't have to wait for the next version of Visual Studio.

Download Visual Studio 2012

MSDN Subscribers can download now at the MSDN Subscriber Download Page. For volume licensing customers, Visual Studio 2012 products will be on the Volume Licensing Service Center tomorrow. If you want to download Visual Studio 2012 free trial versions, or to download the free Express versions, head over to the the Visual Studio product website.

Azure SDK for both Visual Studio 2012 and Visual Studio 2010

It's also worth noting that the Windows Azure .NET SDK has been updated today as well and you can download versions for either Visual Studio 2010 SP1 or Visual Studio 2012.

The Videos

Here's the 13 short videos showing each of my favorite features in just a few minutes. There are new Entity Framework 5 videos as well, so be sure to scroll all the way down!

CODEC NOTE: These are using HTML5 video and MP4. If you are using a browser that doesn't support that codec, click the Header links to go to the ASP.NET site directly and the videos will stream with Silverlight.

Model Binding

HTML Editor

CSS Editor

JavaScript Editor

Page Inspector

ASP.NET 4.5 Web Forms Strongly Typed Data Controls

Web Publishing Improvements

ASP.NET MVC 4

ASP.NET Web API

Bundling and Optimization

SignalR and Web Sockets

Async and Await

OAuth in the Default ASP.NET 4.5 Templates

Entity Framework 5

There are also 5 new Entity Framework videos done by Rowan Miller that show new features of the new Entity Framework 5 as well as walk you through Code First vs. Model First vs. Database First. They are excellent screencasts and I recommend them.

I want to write code:

I want to use a visual designer:

EF5 is the newest version of Entity Framework. These short videos and step-by-step walkthroughs will get you started with the new EF5 features

  • Enum Support in Code First - The domain classes that make up your Code First model can now contain enum properties that will be mapped to the database.
  • Enum Support in EF Designer - Using the EF Designer you can now add enum properties to your entities.
  • Spatial Data Types in Code First - Spatial data types can now be exposed in your Code First model using the new DbGeography and DbGeometry types.
  • Spatial Data Types in EF Designer - Spatial data types can now be used in the EF Designer using the new DbGeography and DbGeometry types.
  • Table-Valued Functions - Table-valued functions (TVFs) in your database can now be used with Database First models created using the EF Designer.
  • Multiple Diagrams per Model - The EF Designer now allows you to have several diagrams that visualize subsections of your overall model. This allows larger models to be broken up into multiple smaller diagrams. You can also add color to the entities to help identify sections of your model.

Related Links

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Introducing LyncAutoAnswer.com - An open source remote worker's Auto Answer Kiosk with Lync 2010

August 15, '12 Comments [11] Posted in Lync | Remote Work
Sponsored By

The name badge on my door in Redmond, Washington says "Virtual Scott Hanselman" because I'm not there!Last month I did a blog post called "Introducing Lync 2010 Super Simple Auto Answer Video Kiosk with Full Screen" where I rewrote the original Embodied Social Proxy software that I'd borrowed from Microsoft Research and just made a better "auto answer client" for Lync. (Lync being the Microsoft Unified Communications software that includes phone calls, IMs and video chats. You get Lync with Office 365.)

This auto-answer software automated the Lync client. You'd still run the Lync client and see the Lync client show up in the Windows taskbar. However, sometimes you might want a simpler "kiosk" solution where the manager end user can't even see Lync or know that it's there. Lync calls this "UI Suppressed" mode. In this mode YOU are Lync and you have to automate the entire solution, paint the video, and manage events. You are using the Lync transport but providing all the UI. The benefits of UI Suppressed mode is that the user can't mess it up or fiddle with Lync. This can be useful in CRM applications where you might want chat and video embedded in some larger system where the user doesn't need to know you're using Lync.

In my case, I want people to come by my physical office in Redmond, Washington - where I am NOT - and sit down and have everything Just Work™. I decided I needed both a Kiosk and a non-Kiosk version. I started coding and realized not only that I was in over my head but also that the idea of a UI Suppression in Lync was in need of an abstraction. The ideas were high level and general but the Lync 2010 SDK code was, in my estimation, rather too low level to make it super easy. Why not wrap Lync and make a reusable library.

I reached out to Tom Morgan in the UK who knows Lync backwards and forwards and works for Modality Systems, a Lync and Unified Communications consultancy. I pitched him the idea - remotely, over Lync, in fact - and we got to pairing. I though it was a problem worth solving that could help not only the Lync community but also Remote Workers everywhere. Big thanks to Tom's bosses at Modality Systems for trusting Tom's judgment with this little weekend project! Feel free to thank them in Tom's blog post on the subject. ;)

Tom created a project on GitHub called Lync-UISuppression-VideoAutoAnswer that includes a WPF control and Lync wrapper abstraction to make UI Suppressed Lync applications easier. Then we updated my LyncAutoAnswer GitHub project to use Tom and Paul Nerney's new library! The project now includes BOTH a UI Suppressed AND non-UI Suppressed version. Tom and friends also redesigned the UI Suppressed version to be more "kiosky" and brighter so people could walk by and immediately know if I was busy or not.

http://lyncautoanswer.com

I am happy to announce (or re-announce) the LyncAutoAnswer client at LyncAutoAnswer.com as a collaboration by Tom Morgan from Thought Stuff and Paul Nearney from CodeLync and me.

Here's a few screenshots of the UI Suppressed version that you can download today to setup your own Lync based remote kiosk.

image

Here I'm away at a conference. Note that not only does the color change but my status message from Lync presence updated as well. The headshot comes directly from Lync and Active Directory.

image

The general idea is simple. You create a Lync account that is NOT you; it's an account for your cart and the one you will call. Mine is called "Cart #7." I made a Domain Account that does NOT have the ability to login to a desktop. It doesn't have file system or network share access, it can only use Lync. Then I setup my remote machine to auto logon when it boots up. I also disabled it's power management and screensaver as this is a dumb kiosk.

The video works!

Then you change the Lync Auto Answer settings like this:

<userSettings>
<SuperSimpleLyncKiosk.Properties.Settings>
<setting name="sipEmailAddress" serializeAs="String">
<value>sip:scottha@microsoft.com</value> <!-- THIS IS YOU -->
</setting>
<setting name="LyncAccountDomainUser" serializeAs="String">
<value>DOMAIN\thecart7</value>
</setting>
<setting name="LyncAccountEmail" serializeAs="String">
<value>thecart7@microsoft.com</value>
</setting>
<setting name="LyncAccountPassword" serializeAs="String">
<value><![CDATA[YOUR*CART*PASSWORDISHERE]]></value>
</setting>
</SuperSimpleLyncKiosk.Properties.Settings>
</userSettings>

And that's it! The kiosk does the rest. You can read more about the UI Suppressed version on Tom's blog post and the non-UI Suppressed version on my site. Also, note that UI Suppressed mode needs a registry key changed, but we include those .reg files for ON and OFF, 32- and 64-bit.

Again, Big thanks to Tom, Paul, their bosses, and the spirit of open source. http://lyncautoanswer.com. We look forward to redesigns, forks and pull requests as well as stories of remote work.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Tiny Happy Features #3 - Publishing Improvements, chained Config Transforms and Deploying ASP.NET Apps from the Command Line

August 12, '12 Comments [39] Posted in ASP.NET | ASP.NET MVC | Tiny Happy Features
Sponsored By

(UPDATE: See other Tiny Happy Features)

Publish Profiles are stored with the projectAt some point soon lots of people are going to start writing these epic blog posts about Visual Studio 2012. They will include LOTS of screenshots (some good and some bad), some small code samples and minimal context. I can't speak for other teams; I can only talk about what we worked on. The <AngleBrackets/> folks in Azure Platform and Tools (ASP.NET, IIS, WCF, EF, Azure much and more) have been putting a lot of work into what I sometimes call "Death by a Thousand Tiny Cuts." It's the little irritants that are as frustrating (or more so) as the big missing features.

Rather than a giant super post (although I'll do that at some point) I thought I'd showcase some Tiny Happy Features that the team worked on just because it made life better. Some are large some are small, but all are tiny happy features.

Publishing and Deployment Improvements

Visual Studio 2012 has a number of subtle but significant improvements to publishing. Of course you likely know you can push code to Azure or AppHarbor using Git. You can publish your web app with Web Deploy which I demonstrated at Mix in my talk Web Deployment Made Awesome: If You're Using XCopy, You're Doing It Wrong. You can see a quick closed-captioned video I did of Web Deployment to Azure in just 4 minutes over here.

Visual Studio added web.config transforms a while back so you can have a Web.config along with a Web.debug.config with the changes you want for debug time, and web.release.config for release time. You can add the free SlowCheetah add-on and get transform support for all your config files, not just web.config.

However, things fell down because Web Deploy and Visual Studio didn't have a way to easily represent Dev, Testing, Staging, Production, Whatever. You could have build configurations but they didn't relate to deployments, which doesn't reflect a developer's reality.

Publishing with Environment-specific Configurations

Publish Profiles are either created manually, or now in VS2012 downloaded as .publishsettings from your host and imported into Visual Studio. In Visual Studio 2012 publish profiles are stored along with your code in the Properties folder so they can be checked in and used by others.

Visual Studio 2012 adds deployment config transforms

You can rename a profile whatever you like by changing the name. Here I've named my publish profile "Production."  There's the coolest part.

PublishProfiles live in the Properties folder

I can make a Web.config file with the same name as my Publish Profile and that transform will be run after the build transform.

Even better you can right click on a Transform now and select Preview Transform and see not only the results, but a Diff of the results.

Transformed Web.config ( transforms applied: Web.Release.config, Web.Production.config)

See right there, and in the large image above? It says "Transformed Web.config ( transforms applied: Web.Release.config, Web.Production.config)." Build transforms happen first, then Publish Transforms. Right now you need to create the file with the same name yourself but we'll be adding tooling for this.

This means I can do things in Web.debug.config like changing compilation options while Web.production.config is for changing connection strings, setting log levels, and adding specific Production settings.

Deploying from the Command Line

Deploying your web application from the command line has long been possible but it's been a pretty obscure and frustrating affair. Now that the Publish Profiles can live with the project and Web.config transforms can be chained in you can publish from the command line much easier.

msbuild MySolution.sln /p:DeployOnBuild=true;PublishProfile=Production;Password=poo

If you have a untrusted certificate on the deployment server you haven't added to your local certs you'll need to add AllowUntrustedCertificate=true as an acknowledgement.

I just make a Deploy.bat that looks like this with a %1 for the Profile Name.

msbuild MySolution.sln /p:DeployOnBuild=true;PublishProfile=%1;AllowUntrustedCertificate=true;Password=poo

Then I can just do

Deploy Production

or

Deploy Staging

I've found these outwardly small but impactful changes have made it a lot easier for me to deploy sites. Deployment shouldn't be hard. I stand by my original statement: If you are using XCopy (or Windows Explorer or FileZilla) to deploy your website, you're doing it wrong.

If you are using Web Sites rather than Web Products, head over to the Web Team blog (and subscribe, too) and add your voice to the comments around our teams' plans regarding Website projects and Web Deployment Projects.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Tiny Happy Features #2 - ASP.NET Web API in Visual Studio 2012

August 10, '12 Comments [15] Posted in ASP.NET | ASP.NET Web API | Javascript | Open Source | Tiny Happy Features | VS2012
Sponsored By

REST, POX, and WCF compared to RESTtafarians, a guy with a bag on his head and Darth Vader

(UPDATE: See other Tiny Happy Features)

At some point soon lots of people are going to start writing these epic blog posts about Visual Studio 2012. They will include LOTS of screenshots (some good and some bad), some small code samples and minimal context. I can't speak for other teams; I can only talk about what we worked on. The <AngleBrackets/> folks in Azure Platform and Tools (ASP.NET, IIS, WCF, EF, Azure much and more) have been putting a lot of work into what I sometimes call "Death by a Thousand Tiny Cuts." It's the little irritants that are as frustrating (or more so) as the big missing features.

Rather than a giant super post (although I'll do that at some point) I thought I'd showcase some Tiny Happy Features that the team worked on just because it made life better. Some are large some are small, but all are tiny happy features.

There's Enterprise Web Services that use SOAP and WS-*.* and they are great for many transactional or complex scenarios. Then there are lighter weight RESTful web services or "Web APIs" that use JSON, XML and respect all of the goodness and stability that is the HTTP specification.

WCF is alive and well and ASP.NET is alive and well and there are reasons to use each technology. As this article says very well, "The world of SOAP and the world of HTTP services are very different. SOAP allows us to place all the knowledge required by our service in the message itself" vs. "you can use [Web APIs] to create HTTP services that only use the standard HTTP concepts (URIs and verbs), and to to create services that use more advanced HTTP features – request/response headers, hypermedia concepts etc."

Kelly Sommers wrote what I consider the best explanation of REST out there in "Clarifying REST." Whether you want to write RESTful resource-focused HTTP services or just POX or POJ (Plain Old XML or Plain Old JSON) services, you can do both with ASP.NET Web API. It's all part of the ASP.NET open source web stack.

Rick Strahl says that ASP.NET Web API is different than other frameworks because "it was built from the ground up around the HTTP protocol and its messaging semantics. Unlike WCF REST or ASP.NET AJAX with ASMX, it’s a brand new platform rather than bolted on technology that is supposed to work in the context of an existing framework. The strength of the new ASP.NET Web API is that it combines the best features of the platforms that came before it, to provide a comprehensive and very usable HTTP platform."

I encourage you to check out Rick's excellent analysis. Here's the features of ASP.NET Web API Rick likes:

  • Strong Support for URL Routing to produce clean URLs using familiar MVC style routing semantics
  • Content Negotiation based on Accept headers for request and response serialization
  • Support for a host of supported output formats including JSON, XML, ATOM
  • Strong default support for REST semantics but they are optional
  • Easily extensible Formatter support to add new input/output types
  • Deep support for more advanced HTTP features via HttpResponseMessage and HttpRequestMessage
    classes and strongly typed Enums to describe many HTTP operations
  • Convention based design that drives you into doing the right thing for HTTP Services
  • Very extensible, based on MVC like extensibility model of Formatters and Filters
  • Self-hostable in non-Web applications 
  • Testable using testing concepts similar to MVC

ASP.NET Web API

There's some lovely new samples at this Git Repository. Just "git clone https://git01.codeplex.com/aspnet" or download the zip. You can also familiarize yourself with ASP.NET and the Web API at the new http://www.asp.net/webapi site.

By the way, I'll be publishing a bunch (13!) of new videos showcasing Web API plus a lot of other Tiny Happy Features next week on the 15th. Each video will only be 5 minutes long and will be a great way to get up to speed on all the new tech over lunch.

To use the samples, follow the instructions on Henrik's blog post announcing them.

Here's one nice little sample that will perhaps cause you to rethink what you can accomplish with ASP.NET web technologies. It's a console application that hosts ASP.NET Web API. To be clear, there's no IIS involved.

In the setup instructions we have to register a port and user with HTTP.sys so the Operating System knows it's OK for send our little self-hosted app HTTP traffic. If you're familiar with WCF you may have done this before.

Here's the server. It's a Console App, minus error handling for clarity.

class Program
{
static readonly Uri _baseAddress = new Uri("http://localhost:50231/");

static void Main(string[] args)
{
// Set up server configuration
HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(_baseAddress);

config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);

// Create server
var server = new HttpSelfHostServer(config);

// Start listening
server.OpenAsync().Wait();
Console.WriteLine("Listening on " + _baseAddress + " Hit ENTER to exit...");
Console.ReadLine();
server.CloseAsync().Wait();
}
}

That code sets up a route, starts the self-hosting process, and waits. Here's a controller at http://localhost:50231/Contact that will ECHO whatever contact you HTTP POST to it as content-type JSON. Note that Contact is a C# type as a parameter to Post().

public class ContactController : ApiController
{
public Contact Post(Contact contact)
{
return contact;
}
}

If I want, I can do a POST from another command line using curl and send some JSON into the server.

POSTing JSON from CURL to ASP.NET Web API

Here's the actual command line. The JSON is echo'ed back.

C:\>curl -X POST -H "Content-Type: application/json" -d "{ Name: 'Scott Guthrie', Age: 67}" http://localhost:50231/api/Contact

That's from the command line but I can also use System.Net.Http.HttpClient to make a call from .NET if I like:

HttpClient client = new HttpClient();

Contact contact = new Contact {
Name = "Henrik",
Age = 100
};

// Post contact
Uri address = new Uri(_baseAddress, "/api/contact");
HttpResponseMessage response = await client.PostAsJsonAsync(address.ToString(), contact);

// Check that response was successful or throw exception
response.EnsureSuccessStatusCode();

// Read result as Contact
Contact result = await response.Content.ReadAsAsync<Contact>();

Console.WriteLine("Result: Name: {0} Age: {1}", result.Name, result.Age);

See how the C# Contact object moves back and forth between the JSON world and C# world easily? That's the JSON.NET open source library making that happen.

JSON and JavaScript is really dynamic, though, and often it's a hassle to try to "deserialize" really dynamic JSON objects into strongly-typed .NET structures. JSON.NET and ASP.NET Web API's model binding offer a happy medium - a middle ground - called JToken.

public class ContactController : ApiController
{
public JToken Post(JToken contact)
{
return contact;
}
}

Check out the watch window as the JSON comes in:

Using JToken to catch a JSON payload

Using JToken gives me a dynamic container but also a DOM-like navigation model. But if that's not dynamic enough for me, why can't my method's parameter just take a "dynamic."

C# is statically typed, sure, but that doesn't mean I can't statically type something dynamic. ;)

Again, note the watch window.

Using dynamic to catch JSON post payloads

See how JSON is moving around the system without any impedance mismatch. The power of C# isn't slowing down the flexibility of JavaScript and JSON.

It makes me happy when things work as they should.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.