Shubham Aggarwal
What is RESTful behaviour?
â—Ź An architectural style to expose operations upon a
resource
What is a Resource?
â—Ź Anything which can be sold
Not to be inferred as an item which
can be sold but anything which
attracts money
Operations on a Resource
â—Ź GET: Retrieve a resource
â—Ź POST: Add a resource
â—Ź PUT: Update a resource as a replacement (more on coming
slide)
â—Ź DELETE: Remove a resource
More operations
â—Ź PATCH: Update a resource, specific fields
â—Ź OPTIONS: How the servers allows to communicate with,
example,
True rest api design
Six properties which define if an API is truly RESTful (HTTP
Standards):
1. Client Server Model
2. Stateless
3. Cache
4. Uniform Interface
5. Layered System
6. Code On Demand (Optional)
Client Server model
â—Ź Complete separation: Allowed to evolve and expand
independently from client
â—Ź API versioning so that clients are decoupled while
extending API
â—Ź Deprecation support
Stateless
â—Ź Each call is independent from each other
â—Ź No use of sessions
â—Ź Each call contains necessary data in itself, such as the
API key, access token, user ID, etc
â—Ź Store state only at client-side
Cache
â—Ź Encourage storage of cacheable data
â—Ź Response can stored based on TTL
â—Ź Explicitly mention if GET should not be cached in
response (using header “Cache-Control” or “Expires”)
â—Ź Cacheable: GET
â—Ź Non-cacheable: PUT, DELETE
Uniform Interface
â—Ź API should have a uniform interface in sense of request
and response
â—Ź Allows client to talk to server in a single standard
(HTTP) and language (JSON or GraphQL or XML)
Layered System
â—Ź Different layers and that shit !
Code on demand
â—Ź Only optional constraint
â—Ź Allows for code or applets to be transmitted via the API
for use within the application
â—Ź Struggling for adoption as not possible in multi-language
environments
Spring boot
â—Ź Framework
â—Ź Convention over configuration
â—Ź Ease of development, built upon Spring MVC
â—Ź Excellent use of Template Design pattern for quick TTM
â—Ź Singleton Flyweight pattern to manage beans
â—Ź Front Controller pattern to manage requests
Code clinic: getting started
$ spring run app.groovy
Code clinic: Annotations in spring
â—Ź @SpringBootApplication
â—Ź @Component
â—‹ @Controller
â–  DispatcherServlet finds @RequestMapping on classes which are
annotated using @Controller but not with @Component
â–  @Component and @Controller are same with respect to bean creation
and dependency injection but later is a specialized form of
former
â—‹ @Service
â—‹ @Repository
â–  catch Platform specific exceptions and rethrow them as one of
Spring’s unified unchecked exception
Code clinic:
MongoDB entity
design
Code clinic:
Define
connection
properties
Code clinic:
define REST APIs
Code clinic:
define repository
Code clinic:
profiling
Code clinic:
executable jar
Code clinic: RUN
Pranam

Spring Boot

  • 1.
  • 2.
    What is RESTfulbehaviour? â—Ź An architectural style to expose operations upon a resource What is a Resource? â—Ź Anything which can be sold Not to be inferred as an item which can be sold but anything which attracts money
  • 3.
    Operations on aResource â—Ź GET: Retrieve a resource â—Ź POST: Add a resource â—Ź PUT: Update a resource as a replacement (more on coming slide) â—Ź DELETE: Remove a resource
  • 4.
    More operations â—Ź PATCH:Update a resource, specific fields â—Ź OPTIONS: How the servers allows to communicate with, example,
  • 5.
    True rest apidesign Six properties which define if an API is truly RESTful (HTTP Standards): 1. Client Server Model 2. Stateless 3. Cache 4. Uniform Interface 5. Layered System 6. Code On Demand (Optional)
  • 6.
    Client Server model â—ŹComplete separation: Allowed to evolve and expand independently from client â—Ź API versioning so that clients are decoupled while extending API â—Ź Deprecation support
  • 7.
    Stateless â—Ź Each callis independent from each other â—Ź No use of sessions â—Ź Each call contains necessary data in itself, such as the API key, access token, user ID, etc â—Ź Store state only at client-side
  • 8.
    Cache ● Encourage storageof cacheable data ● Response can stored based on TTL ● Explicitly mention if GET should not be cached in response (using header “Cache-Control” or “Expires”) ● Cacheable: GET ● Non-cacheable: PUT, DELETE
  • 9.
    Uniform Interface â—Ź APIshould have a uniform interface in sense of request and response â—Ź Allows client to talk to server in a single standard (HTTP) and language (JSON or GraphQL or XML)
  • 10.
    Layered System â—Ź Differentlayers and that shit !
  • 11.
    Code on demand â—ŹOnly optional constraint â—Ź Allows for code or applets to be transmitted via the API for use within the application â—Ź Struggling for adoption as not possible in multi-language environments
  • 12.
    Spring boot â—Ź Framework â—ŹConvention over configuration â—Ź Ease of development, built upon Spring MVC â—Ź Excellent use of Template Design pattern for quick TTM â—Ź Singleton Flyweight pattern to manage beans â—Ź Front Controller pattern to manage requests
  • 13.
    Code clinic: gettingstarted $ spring run app.groovy
  • 14.
    Code clinic: Annotationsin spring ● @SpringBootApplication ● @Component ○ @Controller ■ DispatcherServlet finds @RequestMapping on classes which are annotated using @Controller but not with @Component ■ @Component and @Controller are same with respect to bean creation and dependency injection but later is a specialized form of former ○ @Service ○ @Repository ■ catch Platform specific exceptions and rethrow them as one of Spring’s unified unchecked exception
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.