Good REST CRUD APIs_WS45

Post on 14-Apr-2017

93 views 3 download

Transcript of Good REST CRUD APIs_WS45

Good REST CRUD APIs

WS45

Woolery, Matthew A Govindu, Madanamohan R

Carstensen,Robert L Bhogireddy, Chandu Karri, Venkatesh

CONTENTS

What is REST? What makes a good REST API? CRUD HTTP METHODS CRUD IN REST CRUD at User Interface Level Summary Resources

What is REST?• REST == “REpresentational State Transfer”• It is an architectural style for designing

distributed systems, an approach to communication that is often used in the development of web services.

• The use of REST is often preferred over the more heavyweight SOAP.

• REST permits different data formats such as JSON,XML,HTML etc.

• Resource-based• Representations

Web

Ser

ver

HTTP POST URL 3PO(HTML/XML)

HTTP GET request URL 1

HTTP responseURL to submitted PO

PartsList

PartData

PO

HTTP responseResponse(HTML/XML doc)

HTTP responseResponse(HTML/XML doc)

HTTP GET request URL 2

5Reference from RESTANDSOAP_WS63

Resource-based

• Things vs, actions• Nouns vs. verbs• Resources are identified by URIs

RepresentationsExample:• Resource: Student• Service: Student information• Representation: Student name, GPA,

Student major, address, contact number.

What makes a good REST API?The REST architectural style describes 6 constraints:

1. Uniform interface2. Stateless3. Client-server4. Cacheable5. Layered system6. Code on demand

• Following all these constraints means service is strictly RESTful.• Violating anyone of these will not give strict RESTful service

CRUD The acronym CRUD refers to all of the

major functions that are implemented in relational database applications. Each letter in the acronym can map to a standard SQL statement, HTTP method (this is typically used to build RESTful APIs)

Operation SQL HTTP DDS

Create INSERT PUT / POST write

Read (Retrieve) SELECT GET read / take

Update (Modify) UPDATE POST / PUT/ PATCH write

Delete (Destroy) DELETE DELETE dispose

CRUD Operation HTTP MethodCreate POSTRead GETUpdate PUT and/or PATCHDelete DELETE

HTTP METHODS – CRUD IN REST

• Both PUT and POST can create resources; the key difference is that POST leaves it for the server to decide at what URI to make the new resource available.

• PUT dictates what URI to use; The significant point about PUT is that it will replace whatever resource the URI was previously referring to with a brand new version, hence the PUT method being listed for Update as well.

CRUD Operation HTTP MethodCreate POST

Read GET

Update PUT and/or PATCH

Delete DELETE

CRUD at User Interface level• CRUD is also relevant at the user interface level of most applications.• For example consider your phonebook. The software of phonebook must

allow the user to:

a) Create or add new entriesb) Read, retrieve, search, or view existing entriesc) Update or edit existing entriesd) Delete/deactivate/remove existing entries

• Without at least these four operations, the software cannot be considered complete.

SUMMARY:

• Violating any constraint other than Code on Demand means service is not strictly RESTful

• Many HTTP services model CRUD operations through REST or REST-like APIs .

• With all the four CRUD operations, an application is said to be complete.

Sai Venkat Poorna Chandu Bhogireddy Govindu, Madanamohan R

Karri Venkatesh Carstensen,Robert L Woolery,Matthew A