Ellerslie User Group - ReST Presentation

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Notes on slide 1

    Uri’s are considered opaque – don’t try to pull them apart to infer additional meaning, you can only reliably rely on the representations returned from the GET’ing the uri and it’s associated metadata in headers to discover meaning about the resource.

    When you GET a resource you pull back a representation, it could be anything.Not all resources will provide enough fidelity to round-trip them.Representations should be strict out, loose in... This could mean using an XSD to validate output your service produces, but to be quite forgiving with what a client posts or puts back i.e. Using xpath to fetch only the elements you require, and to default missing elements to reasonable values.

    Unlike web services, which are effectively remote procedure calls, normally aligned with business processes – REST has a set of verbs, and each verb has a specific set of behaviour, working at a resource level.

    Add System.ServiceModel.Web reference.AddWebGet attributes.Add UriTemplate parameter to WebGet attribute.*Change wsHttpBinding to webHttpBindingExplain lack of “Self” or “Links” to related resources – need to be manually injected into DTO (Linq is good for this)

    Create service project.Remove default service, clean up the web.config.Select AdventureWorks.Select just tables.Add ADO.Net Data Service Item (under web tab, easier to find that way)Set the missing parameter on DataService... Set the access rules for entities and operations to be “free for all”.

    Show navigating to a workspaceDrill into Employee collectionDisplay first EmployeeDisplay contact details for first EmployeeDisplay gender property of employeeDisplay department history for a shift...

    Show navigating to a workspaceDrill into Employee collectionDisplay first EmployeeDisplay contact details for first EmployeeDisplay gender property of employeeDisplay department history for a shift...

    Add “SystemEntities” class exposing Queryable set of process DTO’s Process are returned by query via System.Diagnostics.Process.GetProcesses.Mention that we need to let ADO.Net data services know what the key is for out entity – and for that we need to reference another assembly: System.Data.Services.Client

    Favorites, Groups & Events

    Ellerslie User Group - ReST Presentation - Presentation Transcript

    1. REST
      REpresentationalState Transfer
    2. REST - Theory
      Resources
      Representations
      Verbs
      Links
      Headers
      HTTP Status Codes
    3. Resources
      A resource is identified by a Uri.
      Uri’s are considered Opaque.
      http://localhost/api/customers
      http://localhost/api/customers/1
    4. Representations
      Fetching a resource returns a Representation.
      Representations have a content type i.e. text/xml, application/json, text/html etc.
      <customer>
      <self>http://localhost/api.svc/customers/12</self>
      <organisation>DevDefined</organisation>
      <id>1</id>
      <orders>
      http://localhost/api.svc/customers/12/orders
      </orders>
      </customer>
    5. Verbs
      • HTTP Verbs are used to operate on resources.
      • GET must be Side Effect Free
      • PUT must be Idempotent.
    6. Links
      Links are returned in representations.
      Clients follow links, allowing them to transition state.
      Using Links can provide elegant ways to scale out or integrate 3rd party services.
    7. Headers
      If-Modified-Since
      Etag
      Cache-Control
      Accept
      Content-Type
      Authorization
    8. HTTP Status Codes (Just a few...)
    9. Demos
      WCF – Building a Simple Rest Service
      Linq & REST – ADO.Net Data Services
      Entity Framework
      Custom classes
      MVC meets REST - MonoRail
      OAuth – RESTful Authorization
    10. Demo #1
      WCF Demo - A quick tour of a WCF REST service.
      webHttpBinding
      WebGetvsWebInvoke
      UriTemplates
      GET, POST, PUT, & Delete
      Changing the representation.
    11. Fresh to Fiddler?
      Fiddler is very useful when developing REST services.
      There are some catches for first time users:
      Disable IPV6 in Fiddler when using Cassini (it doesn’t like the ::1 loopback address)
      Use “.” after localhost when testing with IE 7 to stop proxy being bypassed.
      i.e. http://localhost.:8080/api.svc/customers/
      FireFox users - you need to manually configure proxy settings.
    12. WCF Gotchas
      Exceptions end up as 500 errors on client.
      You need to explicitly set status for non-server errors (i.e. For invalid requests)
      Uri Templates are fussy
      Trailing slashes will cause a match to fail, contrary to many peoples expectations.
      HTTP Method names are case-sensitive.
      Using “Post” instead of “POST” can make for confusing 405 errors 
      The input/output Representation format is defined at the contract operation level.
      Targeting multiple representations “across the board” is ugly.
      Support for linking resources is non-existent.
    13. Demo #2
      ADO.Net Data Services (Was Astoria)
      Building Service using ADO.Net Entity Framework.
      Exploring Query Syntax.
    14. Entity Framework
      Using EF - Out of scope 
      However... Provides easy way to quickly play with Astoria.
      Add Item -> Entity Model
      Use AdventureWorks database, just the tables should do, call it “AdventureWorks”
      Add Item -> ADO.Net Data Service
      Edit the .cs file, set entities class for service to AdventureWorksModel.AdventureWorksEntities.
      Alter InitializeService method to look like this(Don’t do this for production use)
      public static void InitializeService(IDataServiceConfigurationconfig)
      {
      config.SetEntitySetAccessRule("*", EntitySetRights.All);
      config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
      }
    15. Querying -Simple
    16. Querying – Advanced
    17. Custom Objects – Demo #3
      ADO.Net Data Services isn’t limited to the EF.
      Anything implementing IQueryable interface will work too.
      Let’s try!
    18. Implementation
    19. ADO.Net Data Entities - Client
      Entities comes with a .Net Client.
      Found in the System.Data.Services.Client assembly.
      Client allows Linq -> Uri -> Linq -> Whatever.
      With different Types on the client and Server!
      Client types can be POCO objects, even if the server side representations are not.
      [DataServiceKey(...)] attribute required to support non-GET requests.
      Client implements a “unit of work” like pattern, allowing changes to be collected and then persisted at once.
      Changes can be batched in a single request (though this can be viewed as a perversion of HTTP principles).

    + Alex HendersonAlex Henderson, 3 months ago

    custom

    185 views, 0 favs, 0 embeds more stats

    This presentation covers ReST and implementing ReST more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 185
      • 185 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 4
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories