Lightweight Approach to Building Web APIs with .NET
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Lightweight Approach to Building Web APIs with .NET

on

  • 1,177 views

Traditional .NET development frameworks tend to be big, and cover all possible eventualities, and for many projects this is A Good Thing. But for just as many, if not more, projects, a full one size ...

Traditional .NET development frameworks tend to be big, and cover all possible eventualities, and for many projects this is A Good Thing. But for just as many, if not more, projects, a full one size fits all service solution like WCF is just overkill, and adds unnecessary complexity. This is A Bad Thing. In this talk, I'll go over a lightweight, low-ceremony approach to creating a public APIs for the web in .NET. I will show how to use REST and the Nancy framework to create service applications with less code, less cruft and fewer maintenance headaches. We'll follow the super-duper happy path of Nancy, .NET's answer to Ruby's ultra-lightweight Sinatra framework, to create RESTfull API's that takes full advantage of HTTP and it's ubiquity to make building client applications equally enjoyable.

Statistics

Views

Total Views
1,177
Views on SlideShare
1,177
Embed Views
0

Actions

Likes
0
Downloads
4
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Basics
  • Basics
  • Conneq
  • Brug WhenOrderHasNotChanged_ThenReturn304()

Lightweight Approach to Building Web APIs with .NET Presentation Transcript

  • 1. The Lightweight Approach to BuildingWeb Based APIs with .NET Christian Horsdal Independent Consultant @chr_horsdal http://horsdal.blogspot.com
  • 2. AgendaWho Am I?What is “lightweight”RestBucksRESTNancy
  • 3. 3Who Am I?Independent consultantHusband and FatherSome who enjoys Clean code TDD’ing When my soccer team wins Simplicity Whisky
  • 4. What is lightweight?4
  • 5. 5What is lightweight?Low ceremonyLow cruftConventions
  • 6. 6What is lightweight?OpenAgileInexpensive
  • 7. RestBucks7
  • 8. RestBucks8
  • 9. 9REST
  • 10. 10Richardsons Maturity Model Level 3: Hypermedia Level 2: HTTP Verbs Level 1: Resources Level 0: POX-RPC
  • 11. 11REST - ResourcesThe basic building blocks of a web APIAnything with a URIhttp://restbucks.com/menu/http://restbucks.com/orders/http://restbucks.com/order/42/http://restbucks.com/order/42/payment/
  • 12. 12 REST - Representations GET http://restbucks.com/order/19202048/ HTTP/1.1 Accept: application/vnd.restbucks+xml<?xml version="1.0"?><order xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="h <links> <link uri="http://restbucks.com/order/19202048" rel="http://restbucks <link uri="http://restbucks.com/order/19202048" rel="http://restbucks <link uri="http://restbucks.com/order/19202048" rel="http://restbucks <link uri="http://restbucks.com/order/19202048/payment" rel="http://r </links> <location>inShop</location> <cost>7.60000</cost> <items> <item> <name>Latte</name> <quantity>1</quantity> <milk>skim</milk>
  • 13. 13 REST - RepresentationsGET http://restbucks.com/order/19202048/ HTTP/1.1Accept: application/vnd.restbucks+json { "Location":inShop, "Cost":7.60000, "Items":[ { "Name":"Latte", "Quantity":1, "Preferences":{ "milk":"skim", "size":"large" } } ], "Status":1, "Links":[
  • 14. 14REST - verbsGETPOSTPUTDELETEHEADOPTIONSPATCH
  • 15. 15
  • 16. 16Why Nancy?“Close” to httpVery, very readable codeVery explicit routingAutomatic content negotiationEmbraces modularityEmbraces IoC/DIEmbraces testingRuns anywhere
  • 17. Nancy Basicspublic class MainModule : NancyModule{ public MainModule() { Get["/"] = _ => "Hello from root"; } }public class SubModule : NancyModule{ public SubModule() : base("subpath") { Get["/"] = _ => "Hello from subpath"; }}
  • 18. Nancy BasicsDefines which verbs you acceptspublic class MainModule : NancyModule{ public MainModule() { Get["/"] = _ => "Hello from root"; Post["/"] = _ => DoPost(Request.Form.my_value); Delete["/{id}"] = p => Delete(p.id); Put["/"] = _ => DoPut(Request.Body); Patch["/"] = _ => DoPatch(Request.Body); } }HEAD and OPTIONS and automatic
  • 19. Restbuck on Nancy 19Place an Order
  • 20. RestBucks on Nancy 20View/Cancel/Update
  • 21. RestBucks on Nancy 21Pay an Order
  • 22. RestBucks on Nancy 22XML, JSON or YAML
  • 23. RestBucks on Nancy 23Conditional Gets
  • 24. 26Nancy.TestingTest through the whole Nancy pipelineTake advantage of IoC/DI…Or not
  • 25. 27Why Nancy?“Close” to httpVery, very readable codeVery explicit routingAutomatic content negotiationEmbraces modularityEmbraces IoC/DIEmbraces testingRuns anywhere
  • 26. 28Why REST + NancyLightweight Low ceremony Low cruft Follows conventions Open Agile
  • 27. 29More …RestBucks on Nancy: http://github.com/horsdal/Restbucks-on-NancyRest in Practice: http://restinpractice.com/book.htmlNancy: www.nancyfx.orgMe: Twitter: @chr_horsdal Blog: horsdal.blogspot.com Email: c.horsdal@gmail.com