January 2018
Intermediate to advanced
414 pages
10h 29m
English
We will use HTTP POST when we try to create a resource, so if we try to add new customers, we will post a new resource to our customer URL /customer/. We can do this simply with this code:
package com.microservices.chapter3import org.springframework.beans.factory.annotation.Autowiredimport org.springframework.web.bind.annotation.*import java.util.concurrent.ConcurrentHashMap@RestControllerclass CustomerController { @Autowired lateinit var customers : ConcurrentHashMap<Int, Customer> @RequestMapping(value = "/customers", method = arrayOf(RequestMethod.GET)) fun getCustomers() = customers.map(Map.Entry<Int, Customer>::value).toList() @RequestMapping(value = "/customer/{id}", method = arrayOf(RequestMethod.GET)) fun getCustomer(@PathVariable ...Read now
Unlock full access