ASP.NET You're doing it Wrong. An Introduction to Nancy
mat-mcloughlin.net
mat-mcloughlin.net
No its not.
"If you don't need all the ways you can customize ASP.NET MVC"
Nancy is pluggable at pretty much any point. You don't like the way routing works in Nancy, plug it. Don't like the base module, plug it.
Nancy is far more extensible than WebAPI or MVC.
Having said that, anything you can do in WebAPI / MVC you can do in Nancy, and anything you can do in Nancy, you can do in WebAPI / MVC
Nancy just has a nicer API.
In your opinion.
A lot of older developers don't like the Func<>iness of some of these newer frameworks. Just something to consider.
He does know about WebAPI.
They both have differences, and are equally valid choices. Aside from anything else, I give Nancy time because I'd love to see more open source independent development on the .NET platform.
Its routing is rubbish - waiting for V2 for fixed routing (AttributeRouting support so its not hidden away)
Its terrible to extend.
Its slower than Nancy.
Its hard to test out of the box.
Guess what, your website is an API, it just happens to return text/html instead of some other format you specify. If you use MVC and WebAPI, you're doing it wrong.
Also...
http://weblogs.asp.net/shijuvarghese/archive/2013/07/30/writ...
vs
http://www.marcusoft.net/2013/01/NancyTesting3.html
Sums up WebAPI for me.
SpringMVC + JAX-RS1/2
RoR + Sinatra
A web-app using some framework + NodeJS for API
There's nothing wrong with that as you may want to have different models or different configurations (throttling or whatnot).
Using MVC-based framework for your API endpoint is overkill.
WCF's only benefit is TCP bindings. If you're doing any HTTP stuff, stay clear of WCF.
Your issues with it might have more to do with you.
Odd that the two single replies I got are a couple of bulldogs desperately shooting any alternative to this submission down.
Configuration is a black art: it involves configuring the various WCF interfaces/components in XML. Because of the poor documentation and bugs this can be quite a lot of work. It was quite obviously architected to be used with a configuration UI - it's similar to XAML and IIS in that respect - only Microsoft never bothered making the investment the way they did for IIS + XAML.
It's also buggy - XML parsing in particular is broken - and the default serializers are horribly slow.
It's extremely extensible, but extension requires considerable work. A lot of the base classes are either sealed or internal (or both), which just exasperate this. Without either the source, the tests, proper documentation or the ability to extend existing implementations it turns a job which should take an engineer an hour into a job that will take them 3 months.
So basically, Microsoft have done done everything to make using WCF in anything but the most basic scenarios hard and expensive.
As others have said, if you're doing anything over HTTP then you're better off using either Web API or better yet ServiceStack. I have good experience with the latter.
I've implemented and used WCF in very large financial systems, under enormous loads pushing absolutely massive amounts of data around. These are very complex systems I am talking about, and WCF was used in many capacities, one of which was as a HTTP Restful service layer (and given that we also used it through queueing, and over TCP, it added a consistency to the stack).
It certainly wasn't perfect (the configuration happens to be a particular point of irritation), but it wasn't a pain-point at all. It just was a non-issue and did the job, and was no engineering challenge whatsoever.
But, I suppose, it was "basic" in that we looked to WCF as a service front-door, and didn't actually see any need to alter it much, in the same way that we don't modify the kernel of the Linux instances that we work on or the source code of the nginx variants we use. We have a different domain that is where we add value, and building (or extending) a service handler like that would have been a gigantic waste of time.
Which, I suspect, it is for most people who do so. People have this intrinsic desire to seemingly make their own tasks more difficult for often ill-conceived or illusory goals.
Trying to do a phased replacement of existing J2EE SOAP webservices without the ability to change the clients (meaning that you need wire-level compatible) and you'll see just how hard WCF is to extend.
The fact that it IS possible to do that kind of integration is a testament to just how powerful the framework is. It's just a shame that Microsoft didn't spend an extra 5% effort on the documentation (or just open sourced it).
I should add that we're currently using WCF as an integral part of our system as despite the drawbacks being able to support TCP (and MSMQ etc) and everything else in one framework is worth the extra complexity. Plus we have a lot of organizational knowledge of WCF now.
I used to be like you, think WCF was the bee's knees.
WCF promote poor service design, in an untestable manner, has no real support for DI, has terrible configuration, unhelpful exceptions, faults, message size limitations that cause headaches, horrifically slow. The only benefit to WCF is TCP endpoints. End of story.
;)
Um...okay. That says enough. End of story.
I'm glad MSFT is moving away from that.
WCF is fine until you need to extend it. Nancy, MVC, Web Api are much easier to extend.
Plus WCF needs all sorts configuration stupidity which alternatives just don't have.
Nancy is cool and i'd definitely consider using it in the future but for now, it was easier to port over our api from MVC4 to a much more familiar structure.
Forms auth is done by calling this.RequiresAuthentication(); you can implement an extension method to do an ApiKey check in about 5 lines of code :)
- content negotiation (basic building block of hypermedia APIs),
- authentication (and ensure SSL is used when authenticated),
- most importantly, HTTP caching, where
-- unauthenticated users get cached content, authenticated users don't,
-- vary on representation negotiations (media type, encoding, and language),
-- cache is located on server and in browser.
In other words, take basic advantage of HTTP to improve security and performance. Taken together, the requirements listed above comprise a problem of only moderate complexity, and are fundamental to flexible, high performance web apps. Accomplishing it in ASP.NET MVC/Web API is painful and relies on the inconsistent, malfunctioning, horrifically designed ASP.NET response caching module.
Show me a framework that does the above and makes it reasonable to build hypermedia APIs, and you've got yourself a convert.
For entering the code, I am using my favorite (programmable) text editor and believe it is working very well. Otherwise I use some scripts I've written in my favorite scripting language.
To do this development I read through about a cubic foot of books and 4000+ Web pages of documentation, nearly all from Microsoft's Web site.
For the development I struggle some with 'scope of properties' in CSS (which apparently is nearly never discussed) and much of the documentation, but otherwise from the server farm architecture to the computing to be done down to the lines of code and documentation, there are no problems. E.g., for a single Web page, say, X, there is a file X.ASPX, and it has some options, some static HTML and CSS, some 'event handlers', e.g.,
Sub Page_Init
Sub Page_Load
Sub Page_PreRender
Sub Page_Unload
some Visual Basic
code, a lot of use of classes from
ASP.NET, ADO.NET, etc., and
some include files for CSS,
functions, classes, etc. Fine.And I don't have even as much as a weak little hollow hint of a tiny clue what MVC is or why I should want or need it. The explanations of just why I should want MVC look to me as burdensome and totally meaningless distinctions and constructions for no good reason. Same for a 'framework'. Same for Nancy and everything else in the OP.
E.g., the OP talks about GET and POST "methods". I don't do those things -- IIS and ASP.NET handle those for me. If I want the actual post data, then it's available to me via some ASP.NET classes. But the code I write doesn't deal very directly with GET or POST.
And have I found no good explanation of why I shouldn't just continue as I am.
I don't have a clue what OP is talking about.
My guess is that MVC, Nancy, etc. are for programmers with backgrounds in Web development on Linux who want to program on Windows and there use programming tools and techniques they used on Linux instead of just the usual Windows IIS, ASP.NET, etc.
I've already read a cubic foot of books and 4000+ Web pages of documentation, and my work is going fine; why should I junk my work to date, read a lot more documentation, involve myself in more overhead of tools instead of just going my real work?
More documentation can have errors; more tools can take me farther from the real data and can have bugs.
Am I doing something seriously wrong?
You might be absolutely fine not knowing those things, but at some point down the road you are going to be lacking some essential knowledge of how HTTP works. To put it simply: everything - Ruby, PHP, ASP.NET, you name it - uses GET and POST requests underneath it all. Learning about them would be of great benefit to you in the long term.
A slightly inaccurate analogy: you can make a perfectly functional web site with Dreamweaver, and not touch a single HTML tag. It'll work fine, until it doesn't, and then you're going to be in a lot of trouble. Given that you don't know what's going on underneath Dreamweaver's GUI, your only option will be to keep hitting 'undo' until it works again.
Same for a 'framework'. Same for Nancy and everything else in the OP.
ASP.NET WebForms is a 'framework', too. They're just different frameworks. WebForms, as the name suggests, is particularly good at creating forms- it has numerous abstractions to help you maintain state. It's great for intranet data gathering/presentation stuff. But the pages are very, very heavy, loaded down with code that never gets used. So it has pluses and minuses. Just like MVC and Nancy.
Some things like making an endpoint that servces json and xml responses is almost trivial on Nancy or ServiceStack, easy in ASP MVC with WebApi, and a pain in webforms.
From what I understand, what I'm using is lighter weight than MVC or anything else being discussed here. So far, I see no problems with what I'm doing.
E.g., for the MVC architecture, I have a server farm and software architecture, and it's simple and more than enough.
If you have "event handlers" like "Page_Init" in a .apsx.vb file then you are using web forms. No other framework has these. They were an attempt in the late 1990s to make the web look like winforms. it worked, to a degree.
> what I'm using is lighter weight than MVC
I doubt it.
> I see no problems with what I'm doing.
That's a different question; I'm sure what you're doing is workable.
> You might be absolutely fine not knowing those things, but at some point down the road you are going to be lacking some essential knowledge of how HTTP works. To put it simply: everything - Ruby, PHP, ASP.NET, you name it - uses GET and POST requests underneath it all. Learning about them would be of great benefit to you in the long term.
Right. But I do understand GET and POST, and, again, via some classes in ASP.NET have access to that data, including raw, if I want it. Occasionally I considered looking at the raw data but too quickly found ASP.NET classes that had the data I wanted already all parsed, etc. in properties of the classes; I don't think I've touched the raw GET/POST data yet.
Yes, ASP.NET does some things for me, e.g., ViewState, which took a while to understand. Okay.
I didn't like the way ASP.NET and IIS handled user session state so just grab a GUID, convert it to a string, put it in a hidden field, and send it to the user. Then on postback, I get the GUID, and that's my session ID for that user. That session ID, just as the string is the key in a little key-value store I wrote as a separately running Visual Basic .NET console application using class instance de/serialization, TCP/IP, and two instances of a .NET collection class (hopefully AVL trees or red-black trees). The key-value store is single-threaded so doesn't need to use the concurrent versions of the collection classes. Timings indicate that on a 3.0 GHz single core processor, the store should be able to send or receive 2000 key-value pairs a second, enough to send 1000 Web pages a second.
As far as I know, I don't really use Web Forms. I use placeholders, tables, buttons, and text boxes via static HTML and/or the corresponding ASP.NET classes. ASP.NET builds a big tree of all the 'controls', etc., and at 'render time' does apparently a depth first traversal of the tree and scribbles out the corresponding static HTML to send to the user. And if ASP.NET wants to send the user some JavaScript, it writes and sends that, too -- so far have yet to write a single character of JavaScript. Fine with me.
So far my Web pages are next to dirt simple and, with the JavaScript, send from my server (not counting data from ad servers) for about 400,000 bits each. Likely much of the JavaScript is boilerplate and can be shrunk, but that's for later. I have no pull-downs, pop-ups, or roll-overs; each screen is exactly 800 pixels wide; there is some simple text, a few simple images, some push buttons and text boxes, all arranged in tables for layout. Some of the screens have to be a bit dynamic so get generated in loops in Visual Basic code and are not just static HTML, but the only dynamic part is the number of rows in some tables -- we're still talking simple.
I guess, "If it ain't broke, then don't fix it.".
AFAIK, a pull-down is a menu that usually starts near the top of a Web page and 'pulls down' so that its items cover much of the page and let the user click to pick one of the menu options.
I have contempt for pop-ups and also pull-downs so use "ups" for one and "downs" for the other.
Instead of such controls, I prefer a better considered user interface (UI) that doesn't have the screen jump around. Basically for a good user experience (UX), I never want the screen to 'jump' in a way that surprises the user.
A screen that jumps has a UI that is difficult to document succinctly and, thus, usually is not documented well or at all and, then, requires a user to experiement with the UI, assume some truths from some really thin hints, and waste effort. Instead I want the UI to be easy to understand carefully and thoroughly without experiments or guessing.
That said, I love C#, I like ASP.NET MVC, and I absolutely loathe WebForms and VB.NET. Everything about those technologies feels clunky and wrong-headed to me, as if I have been forced to run a race with my arms strapped to my sides. Having learned about HTTP, HTML, and core JavaScript a long time ago, WebForms seems an awkward, highly annoying abstraction that hides the knobs I want to turn while presenting me with hundreds of different knobs about which I don't want to learn.
While not quite so bad, the syntax of VB.NET fills me with unease... everything seems cleaner, clearer, smarter in C#. VB.NET shouts "the author of this code doesn't really like to write code" in the same way that a Prius announces "the owner of this car doesn't like motorsports."
> presenting me with hundreds of different knobs about which I don't want to learn
I certainly haven't been using lots of such knobs. Nearly everything I do in VB.NET and ASP.NET is obviously quite close to really simple HTML and CSS.
As far as I can tell, C# and VB.NET are equivalent ways, different essentially only in syntactic sugar, to get to the basic .NET classes and common language runtime (CLR). C# seems to want to borrow from the especially succinct syntax of C/C++ which I don't like. I prefer the more verbose syntax from the history of Fortran, Basic, PL/I, etc.
E.g., I have essentially no idea what MVC is, what it's for, why one should use it, etc. Similarly for WebForms. Then similarly for Nancy, etc.
So far, my Web pages work fine.