Java Code Examples for ratpack.handling.Context#get()
The following examples show how to use
ratpack.handling.Context#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EmployeeHandler.java From tutorials with MIT License | 5 votes |
@Override public void handle(Context ctx) throws Exception { EmployeeRepository repository = ctx.get(EmployeeRepository.class); Long id = Long.valueOf(ctx.getPathTokens() .get("id")); Promise<Employee> employeePromise = repository.findEmployeeById(id); employeePromise.map(employee -> employee.getName()) .then(name -> ctx.getResponse() .send(name)); }
Example 2
Source File: RedirectHandler.java From tutorials with MIT License | 5 votes |
@Override public void handle(Context ctx) throws Exception { HttpClient client = ctx.get(HttpClient.class); URI uri = URI.create("http://localhost:5050/employee/1"); Promise<ReceivedResponse> responsePromise = client.get(uri); responsePromise.map(response -> response.getBody() .getText() .toUpperCase()) .then(responseText -> ctx.getResponse() .send(responseText)); }