Mini-Training: Let's have a rest

18
LET’S HAVE A REST ! Private and Confidential MAXIME LEMAITRE - 11/04/2013

description

A quick overview on REST : what it is and what it is not. REST has strict contraints and many internet Apis are not so REST. It’s also very popular today because RESTfull services can be consumed easily by any client or device. Soap is also still valid in a few circomstaces. It has never been so easy to create Rest-like services in .net since asp.net Web Api.

Transcript of Mini-Training: Let's have a rest

Page 1: Mini-Training: Let's have a rest

LET’S HAVE A REST !

Private and Confidential

MAXIME LEMAITRE - 11/04/2013

Page 2: Mini-Training: Let's have a rest

Agenda

• Introduction• What it is not, what it is• REST constraints• In the web Industry• SOAP Vs REST• REST-style Service in .NET • Conclusion

Page 3: Mini-Training: Let's have a rest

RESTa vastly misunderstood term

• REpresentational State Transfer is not a–Philosophy essay–Language–Protocol–Standard, RFC–Framework of MS, Google, Facebook, …–Technology–…

Page 4: Mini-Training: Let's have a rest

RESTwhat REST is

• Introduced in 2000 by Roy Fielding– principal author of HTTP and creator of Apache Web Server

• REST is an architecture style– a coordinated set of architectural constraints that restricts the roles and

features of architectural elements, and the allowed relationships between those elements• Client–server• Stateless• Cacheable• Layered system• Uniform interface• Code on demand (optional)

Conforming to these constraints is referred to as being RESTful

Page 5: Mini-Training: Let's have a rest

RESTConstraints

Client – Server

“No restrictions on the nature of the client, on the number of the clients and on communication medium / protocol”

• Separate data storage concerns• Improve user interface portability

across multiple platforms• Improve scalability by simplifying

server components• Components evolve independently

Stateless

“... each request from client to server must contain all of the information necessary to understand the request, and cannot take advantage of any stored context on the server, independent of any requests that may have preceded it »

• Session state is kept on client• Improved visibility because every

exchange is self descriptive• Easier recoverability from partial

failures• Improved scalability on server

Page 6: Mini-Training: Let's have a rest

RESTConstraints

Cacheability

“... the data within a response to a request must be implicitly or explicitly labeled as cacheable or non-cacheable. If a response is cacheable, then a client cache is given the right to reuse that response data for later, equivalent requests.”

• Reduces client to server interactions• Improves efficiency, scalability and

user perceived performance

Layered System

“The layered system style or also popularly referred to as n-layer system allows an architecture to be composed of hierarchical layers by constraining component behavior such that each component cannot "see" beyond the immediate layer with which they are interacting.”

Page 7: Mini-Training: Let's have a rest

RESTConstraint : Uniform Interface

Information is transferred in a standardized formConsidered fundamental to the design of any REST app

• Identification of resourcesEach resource has a URI and is access through a defined set of HTTP methods (GET, PUT, POST, DELETE)

• Manipulation of resources through representationsEach resource can have one or more representations. Such as application/xml, application/json, text/html, etc. Clients and servers negotiate to select representation.

• Self-descriptive messagesRequests and responses contain not only data but additional headers describing how the content should be handled. Such as if it should be cached, authentication requirements, etc.

• Hypermedia as the engine of application state (aka HATEOAS)Clients make state transitions only through actions that are dynamically identified within hypermedia by the server (e.g., by hyperlinks within hypertext). Except for simple fixed entry points to the application, a client does not assume that any particular action is available for any particular resources beyond those described in representations previously received from the server.

Page 8: Mini-Training: Let's have a rest

RESTbig brother

What is the biggest known RESTful System on planet Earth?

World Wide Web

Page 9: Mini-Training: Let's have a rest

RESTful Web ServiceREST for the web

• A RESTful web API (also called a RESTful web service) is a web API implemented using HTTP and the principles of REST– URI (Clean ?)– Internet media types– HTTP Headers– HTTP Response Codes– HTTP Methods

• GET• POST• PUT• DELETE…

• RESTful Web Service uses the existing features of the HTTP protocol. • Layered proxy and gateway components perform additional functions on the

network, such as HTTP caching and security enforcement.

Page 10: Mini-Training: Let's have a rest

RESTin the web industry

• Definition of REST lost its way when popular services emerged calling themselves REST which were not– Having an HTTP server accept GET requests or POST and responding

with XML, JSON or some other data format is not automatically RESTful

• Not so many RESTful services, but many REST-like services and web Api ( loose adherence)– Client scripts– Exposed Operations

Page 11: Mini-Training: Let's have a rest

RESTwhat makes REST-style web services so popular today ?

• Because it’s based on the same constraints that make the Web successful– Web was not designed as an Xml Bus with RPC

• Since it uses standard HTTP features, it is much more simpler, easier, faster and scalable than any other web technology

• REST-styles permits many different data formats (json, xml, …)• REST-styles web services can be consumed easily by any

client or device– Do you know a better way to touch desktop browsers, mobile, tablets for any OS or technology ?

Page 12: Mini-Training: Let's have a rest

REST vs SOAPSOAP web service REST-style web service

Support multiple transport protocols (HTTP, TCP, UDP, and custom transports)

HTTP only and more suitable for access from various browsers, mobile devices etc enabling wide reach.

Enables building services that support multiple encodings (Text, MTOM, and Binary) of the same message type and allows switching between them.

Enables building Web APIs that support wide variety of media types including XML, JSON etc.

Supports building services with WS-* standards like Reliable Messaging, Transactions, Message Security.

Uses basic protocol and formats such as HTTP, WebSockets, SSL, JQuery, JSON, and XML. There is no support for higher level protocols such as Reliable Messaging or Transactions.

Supports Request-Reply, One Way, and Duplex message exchange patterns.

HTTP is request/response but additional patterns can be supported through SignalRand WebSockets integration.

WCF SOAP services can be described in WSDL allowing automated tools to generate client proxies even for services with complex schemas.

There is a variety of ways to describe a Web API ranging from auto-generated HTML help page describing snippets to structured metadata for OData integrated APIs.

Page 13: Mini-Training: Let's have a rest

RESTHow to build a REST-style Service in .NET ?

• Using WCF (deprecated)– Using WebHttpBinding & WebHttpBehavior

• Using Asp.net Web Api– Not part of .NET, open-source as MVC– Strong Support URL Routing to produce clean URLs using familiar MVC style 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– 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– …

Page 14: Mini-Training: Let's have a rest

RESTHow to build a REST-style Service in .NET ?

/api/products/2

Page 15: Mini-Training: Let's have a rest

Conclusion

• REST is a vastly misunderstood term

• REST-styles web services are very popular today because they are simple, easy to use, performant , scalable and can be consumed by any client

• REST-style Vs SOAP ? Both the REST-style and SOAP have advantages and disadvantages when it comes to building services. It’s more related to an architectural Decision.

to rest ...

Page 17: Mini-Training: Let's have a rest

Find out more

• On https://techblog.betclicgroup.com/

Page 18: Mini-Training: Let's have a rest

About Betclic• Betclic Everest Group, one of the world leaders in online gaming, has a unique portfolio

comprising various complementary international brands: Betclic, Everest Gaming, bet-at-home.com, Expekt…

• Active in 100 countries with more than 12 million customers worldwide, the Group is committed to promoting secure and responsible gaming and is a member of several international professional associations including the EGBA (European Gaming and Betting Association) and the ESSA (European Sports Security Association).

• Through our brands, Betclic Everest Group places expertise, technological know-how and security at the heart of our strategy to deliver an on-line gaming offer attuned to the passion of our players.