Hard Prerequisites |
|
Two of the most commonly used Api architectures currently in use are REST and SOAP.
REST is an architecture used in web applications that make it easier for different systems to communicate with each other. They are referred to as stateless, which means that the current state of the system calling the REST api, has no influence on the functionality of the Api. REST was created to fix some of the shortcomings that the SOAP architecture has.
The most common REST endpoints are the following:
GET - Used to fetch data POST - Used to create a new resource PUT - Used to update a specific resource DELETE - Used to remove a specific resource
SOAP is an architecture that makes use of XML for queries. It was created before REST to replace systems at that time that made use of binary messaging.
As part of the examples, let’s assume the url to be https://www.myapi.com
@GetMapping("/employees")
List<Users> all(String item) {
return listOfUsers;
}
Here is a breakdown of the snippet above:
@PostMapping(value = "/posts")
public UserRest createUser(@RequestBody UserDetailsRequestModel requestUserDetails)
{
UserRest returnValue = new UserRest();
UserDto userDto = new UserDto();
BeanUtils.copyProperties(requestUserDetails, userDto);
UserDto createdUser = userService.createUser(userDto);
BeanUtils.copyProperties(createdUser, returnValue);
return returnValue;
Here is a breakdown of the snippet above:
@PutMapping(value = "/contacts/{contactId}")
public ResponseEntity<Contact> updateContact(@RequestBody Contact contact,
@PathVariable long contactId) {
...
return ...
}
Here is a breakdown of the snippet above:
@PatchMapping("/patch")
public @ResponseBody ResponseEntity<String> patch() {
return new ResponseEntity<String>("PATCH Response", HttpStatus.OK);
}
Here is a breakdown of the snippet above:
@DeleteMapping(value = "/posts/{id}")
public ResponseEntity<Long> deletePost(@PathVariable Long id) {
var isRemoved = postService.delete(id);
return new ResponseEntity<>(id, HttpStatus.OK);
}
Here is a breakdown of the snippet above:
Using programs such as Postman, a developer can easily insert the details of the endpoint required and view the results the api returns. It is a widely used software in the development community.
https://www.guru99.com/soap-simple-object-access-protocol.html. https://www.sitepoint.com/developers-rest-api/ https://spring.io/guides/tutorials/bookmarks/ https://www.youtube.com/watch?v=_Py89z5Reus http://www.appsdeveloperblog.com/postmapping-requestbody-spring-mvc/ http://zetcode.com/spring/postmapping/ http://www.appsdeveloperblog.com/putmapping-spring-mvc/ https://www.programcreek.com/java-api-examples/index.php?api=org.springframework.web.bind.annotation.PutMapping https://www.javaguides.net/2018/11/spring-getmapping-postmapping-putmapping-deletemapping-patchmapping.html https://www.javaguides.net/2018/09/spring-boot-2-hibernate-5-mysql-crud-rest-api-tutorial.html http://zetcode.com/spring/deletemapping/ https://www.concretepage.com/spring-boot/spring-boot-rest-example https://www.postman.com/