Initial Changes for RequestLine

This commit is contained in:
Amitabh Tiwari 2022-04-29 18:42:53 +05:30
parent 4bcb36ff41
commit ec0b628fb4
3 changed files with 50 additions and 0 deletions

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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;
}
}