Server Side APIs Flashcards
Frontend
Provides functionality for the user. It deals with the user input and showing output to the user.
Backend
Provides data, algorithms, and logic for the frontend to use.
Model View Controller (MVC)
Is a pattern that divides the application based on responsibility. The end result is that the Model and View are unaware that the other exists. This decouples the Model and View.
Model (MVC) characteristics
- Application state and business logic.
- Only part of the application that talks to the database.
- Model could be classes.
View (MVC) characteristics
- Presents data to a user.
- Accept input from a user.
- Views might be a desktop display, a mobile display, a file output based on a model.
- The View is not the output HTML/UI that displays in the browser or device, it is the code that generates the response.
Controller (MVC) characteristics
- Takes input from the view and passes it to the appropriate model objects.
- Grabs all necessary building blocks and organizes them for the output.
- Takes results from the model and passes them to the appropriate view.
Dependency Injection
Is a design pattern that implements IoC. It inverts control of the instantiation of dependencies from the class using them to a dependency injection container. Rather than instantiating classes with “new” in our class, they will be injected into our class at runtime.
Inversion of Control (IoC)
Is an object-oriented principle that inverts the flow of normal flow of control of an application from a class to a higher layer. It is commonly used in Java Frameworks.
Dependency Injection Container
Is code that creates and injects the dependencies into our class. Spring has a Dependency Injection Container built into it.
Dependency Injection in Spring Boot
- Create an Interface with an Implementation class (CityDao).
- Add the @Component annotation to the implementation class (JdbcCityDao).
- Declare an argument of a constructor using the Interface
public CityController( CityDao cityDao) - Or a variable can be created with the @Autowired annotation but can make Integration/Unit testing more difficult.
@Autowired
private CityDao cityDao;
RESTful Service Design - End Points
- Endpoints should be plural names that define what is being accessed (the entity - hotels, reservations, cities, etc).
- IDs should be sent as Path Variables.
- Filters and Sorting should be sent as Query Parameters.
- Endpoints should reflect the hierarchy of the entities.
RESTful Service Design - CRUD
- What do you want your user to be able to Create? (POST)
- What do you want your user to be able to Read? (GET)
- What do you want your user to be able to Update? (PUT)
- What do you want your user to be able to Delete? (DELETE)
HTTP Response Status Codes
2xx Status Codes can be applied to a controller method using the @ResponseStatus annotation.
4xx Status Codes can be returned by throwing an Exceptions from the Controller Method.