Automating the Use of Web APIs through Lightweight Semantics
Lightweight Approach to Building Web APIs with .NET
-
Upload
christian-horsdal -
Category
Documents
-
view
1.056 -
download
3
description
Transcript of Lightweight Approach to Building Web APIs with .NET
The Lightweight Approach to Building
Web Based APIs with .NET
Christian Horsdal
Independent Consultant
@chr_horsdal
http://horsdal.blogspot.com
Agenda
Who Am I?
What is “lightweight”
RestBucks
REST
Nancy
Who Am I?
Independent consultant
Husband and Father
Some who enjoys
Clean code
TDD’ing
When my soccer team wins
Simplicity
Whisky
3
4
What is lightweight?
What is lightweight?
Low ceremony
Low cruft
Conventions
5
What is lightweight?
Open
Agile
Inexpensive
6
7
RestBucks
8
RestBucks
REST
9
Richardsons Maturity Model10
Level 3: Hypermedia
Level 2: HTTP Verbs
Level 1: Resources
Level 0: POX-RPC
REST - 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/
11
REST - Representations 12
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="http://www.w3.org/2001/XMLSchema" <links><link uri="http://restbucks.com/order/19202048" rel="http://restbucks.com/docs/order<link uri="http://restbucks.com/order/19202048" rel="http://restbucks.com/docs/order<link uri="http://restbucks.com/order/19202048" rel="http://restbucks.com/docs/order<link uri="http://restbucks.com/order/19202048/payment" rel="http://restbucks.com/docs/order
</links><location>inShop</location><cost>7.60000</cost><items><item><name>Latte</name><quantity>1</quantity><milk>skim</milk><size>large</size>
REST - Representations 13
GET http://restbucks.com/order/19202048/ HTTP/1.1
Accept: application/vnd.restbucks+json
{"Location":inShop,"Cost":7.60000,"Items":[{
"Name":"Latte","Quantity":1,"Preferences":{"milk":"skim","size":"large"
}}
],"Status":1,"Links":[{
REST - verbs
GET
POST
PUT
DELETE
HEAD
OPTIONS
PATCH
14
15
Why Nancy?
“Close” to http
Very, very readable code
Very explicit routing
Automatic content negotiation
Embraces modularity
Embraces IoC/DI
Embraces testing
Runs anywhere
16
Nancy Basics
public class MainModule : NancyModule{
public MainModule(){
Get["/"] = _ => "Hello from root";}
}
public class SubModule : NancyModule{
public SubModule() : base("subpath"){
Get["/"] = _ => "Hello from subpath";}
}
Nancy Basics
Defines which verbs you accepts
HEAD and OPTIONS and automatic
public 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);
}}
Restbuck on Nancy
Place an Order
19
RestBucks on Nancy
View/Cancel/Update
20
RestBucks on Nancy
Pay an Order
21
RestBucks on Nancy
XML, JSON or YAML
22
RestBucks on Nancy
Conditional Gets
23
Nancy.Testing
Test through the whole Nancy pipeline
Take advantage of IoC/DI
…Or not
26
Why Nancy?
“Close” to http
Very, very readable code
Very explicit routing
Automatic content negotiation
Embraces modularity
Embraces IoC/DI
Embraces testing
Runs anywhere
27
Why REST + Nancy
Lightweight
Low ceremony
Low cruft
Follows conventions
Open
Agile
28
More …
RestBucks on Nancy: http://github.com/horsdal/Restbucks-on-Nancy
Rest in Practice: http://restinpractice.com/book.html
Nancy: www.nancyfx.org
Me:
Twitter: @chr_horsdal
Blog: horsdal.blogspot.com
Email: [email protected]
29