-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add tiny example * fix basic exmaple * Add server/client exmaples Co-authored-by: Emil Ivanichkov <[email protected]> --------- Co-authored-by: Emil Ivanichkov <[email protected]>
- Loading branch information
1 parent
223aade
commit a9687dd
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import pkg/presto/[route, server] | ||
|
||
proc decodeString*(t: typedesc[string], value: string): RestResult[string] = | ||
ok(value) | ||
|
||
proc validate(pattern: string, value: string): int = 0 | ||
|
||
when isMainModule: | ||
var router = RestRouter.init(validate) | ||
|
||
router.api(MethodGet, "/") do () -> RestApiResponse: | ||
RestApiResponse.response("Hello World", Http200, "textt/plain") | ||
|
||
let restServer = RestServerRef.new(router, initTAddress("127.0.0.1:9000")).get | ||
restServer.start() | ||
|
||
runForever() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import pkg/presto/[route, client] | ||
import ../tests/helpers | ||
|
||
proc hello() {.async.} = | ||
var restClient = RestClientRef.new(initTAddress("127.0.0.1:9000")) | ||
proc helloCall(body: string): string {. | ||
rest, endpoint: "/hello/world", meth: MethodPost.} | ||
let res = await restClient.helloCall("Hello Server!", restContentType = "text/plain") | ||
echo "Server response: ", res | ||
|
||
when isMainModule: | ||
waitFor hello() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import pkg/presto/[route, server] | ||
import stew/byteutils | ||
|
||
proc validate(pattern: string, value: string): int = 0 | ||
|
||
when isMainModule: | ||
var router = RestRouter.init(validate) | ||
|
||
router.api(MethodPost, "/hello/world") do ( | ||
contentBody: Option[ContentBody]) -> RestApiResponse: | ||
echo "Client says: ", string.fromBytes(contentBody.get().data) | ||
|
||
RestApiResponse.response("Hello Client, I am Server", Http200, "textt/plain") | ||
|
||
let restServer = RestServerRef.new(router, initTAddress("127.0.0.1:9000")).get | ||
restServer.start() | ||
|
||
runForever() |