REST/Spring/Mokito Flashcards

1
Q

What is REST

A
  1. Representational state transfer
  2. Architecture style utilising http protocal/methods
  3. Rest Client + Rest Server
  4. using URI to identify each resource
  5. POST, GET, PUT, DELETE
  6. Resource can be ins format json, XML
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is RESTful web service?

A

Web service implemented using REST style.
Usually used for:
export data for another application/system
Example: export all USD trades from ourside

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is in HTTP request/response?

A

request: Http Methods, URI, Http version, Header(key-value pairs), Request Body(msg content)
response: Response code, http version. response header, response body.

Response Code:
200 OK
404 not found

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Implementation of Rest end point?

A

Using Spring framework web

@RestController
@RestMapping(value=”/api/recon”, method = RequestMethod.POST)
public ResponseEntity export(@RequestBody DashboardRequest request);

Using Jersey as a client
Spring:
RestTemplate execute(URL, method, requestCallbacl, requestExtractor)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is Spring IoC container?

A
  1. Core of spring framework, create all the beans,
    resolve dependency between them, keep them alive until time to destroy. Managing the whole life cycle of the bean.
  2. Use Dependency Injection
  3. Most useful one - ApplicationContext
    more features than ‘BeanFactory’
    can resolve text properties in files
    can send event to event listener(ex: when app is started)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Application Main class

A

@SpringBootApplication
= @EnableAutoConfiguration + @Configuration + @ComponentScan

AutoConfiguration helps what?
for Ex: auto configure JdbcTemplate if its present and a DataSource bean are available

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is SpringBoot?

A
  1. A Framework enables fast java app development using spring framework
  2. Easy to use
  3. when embedded tomcat server
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Difference between Mock and Spy

A

Mock
create a complete fake object, is the method is not stubbed, it will do nothing, return null

Spy
created a half real object, if the method is not stubbed, it will execute the actual method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Steps in designing REST Services

A
1.Identify Object Model
each object with a unique : int Id;
2. Create Model URIs
Follow the resource heriachys
/devices
/devices/{id}

/configurations
/configurations/{id}

/devices/{id}/configurations
/devices/{id}/configurations/{id}

  1. Determine Representations - structure, Json, XML
    Collections of Resource - only expose necessary fields to reduce API payload
    Single resource - can expose mode details fields
  2. Assign HTTP Methods
  3. More Actions
    1) Logging
    2) Security
    3) Discovery (retry)
    https: //restfulapi.net/rest-api-design-tutorial-with-example/#object-model
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Constructor Vs setter based DI?

A

Constructor DI:
enforces the order of initialisation
preventscircular dependencies,

Setter DI:
Setter DI allows circular dependencies
It is easy to miss a few setter calls when wiring the application together.
lazy initialisation - Setter-based DI helps us to inject the dependency only when it is required, as opposed to requiring it at construction time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

log4j

A

log4j is a tool to help the programmer output log statements to a variety of output targets. In case of problems with an application, it is helpful to enable logging so that the problem can be located. With log4j it is possible to enable logging at runtime without modifying the application binary.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly