forked from yegor256/takes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTake.java
More file actions
58 lines (55 loc) · 1.68 KB
/
Take.java
File metadata and controls
58 lines (55 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* SPDX-FileCopyrightText: Copyright (c) 2014-2026 Yegor Bugayenko
* SPDX-License-Identifier: MIT
*/
package org.takes;
/**
* Take.
*
* <p>Take is a momentary snapshot of in-server reality, visible to the
* end user via printable {@link Response}.
* For example, this is a simple web server
* that returns "hello, world!" plain text web page:
*
* <pre> new FtBasic(
* new Take() {
* @Override
* public Response act(final Request req) {
* return new RsText("hello, world!");
* }
* },
* 8080
* ).start(Exit.NEVER);
* }</pre>
*
* <p>There are a few classes that implement this interface, and you
* can create your own. But the best way is to start with
* {@link org.takes.facets.fork.TkFork}, for example:
*
* <pre> new FtBasic(
* new TkFork(new FkRegex("/", "hello, world!")), 8080
* ).start(Exit.NEVER);
* }</pre>
*
* <p>This code will start an HTTP server on port 8080 and will forward
* all HTTP requests to the instance of class
* {@link org.takes.facets.fork.TkFork}.
* That object will try to find the best suitable "fork" amongst all
* encapsulated objects. There is only one in the example above —
* an instance of {@link org.takes.facets.fork.FkRegex}.
*
* <p>All implementations of this interface must be immutable and thread-safe.
*
* @see <a href="http://www.yegor256.com/2015/03/22/takes-java-web-framework.html">Java Web App Architecture In Takes Framework</a>
* @since 0.1
*/
@FunctionalInterface
public interface Take {
/**
* Convert request to response.
* @param req Request to process
* @return Response
* @throws Exception If fails
*/
Response act(Request req) throws Exception;
}