Initial Changes for RequestLine
This commit is contained in:
parent
4bcb36ff41
commit
ec0b628fb4
|
@ -0,0 +1,13 @@
|
|||
package com.baeldung.cloud.openfeign.client;
|
||||
|
||||
import com.baeldung.cloud.openfeign.model.Employee;
|
||||
import feign.Headers;
|
||||
import feign.Param;
|
||||
import feign.RequestLine;
|
||||
|
||||
public interface EmployeeClient {
|
||||
|
||||
@RequestLine("GET /empployee/{id}?active={isActive}")
|
||||
@Headers("Content-Type: application/json")
|
||||
Employee getEmployee(@Param long id, @Param boolean isActive);
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.baeldung.cloud.openfeign.controller;
|
||||
|
||||
import com.baeldung.cloud.openfeign.client.EmployeeClient;
|
||||
import com.baeldung.cloud.openfeign.model.Employee;
|
||||
import feign.Feign;
|
||||
import feign.form.spring.SpringFormEncoder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class EmployeeController {
|
||||
|
||||
private static final String HTTP_FILE_EMPLOYEE_URL = "http://localhost:8081";
|
||||
|
||||
@GetMapping("/employee/{id}")
|
||||
public Employee getEmployee(@RequestParam("id") long id) {
|
||||
EmployeeClient employeeResource = Feign.builder().encoder(new SpringFormEncoder())
|
||||
.target(EmployeeClient.class, HTTP_FILE_EMPLOYEE_URL);
|
||||
return employeeResource.getEmployee(id, true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.baeldung.cloud.openfeign.model;
|
||||
|
||||
public class Employee {
|
||||
|
||||
private Long id;
|
||||
private String name;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue