-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add multiple handlers server (#32)
* feat: add multiple handlers server * fix: missing relative_url to root * fix: update CHANGELOG.md Co-authored-by: Simon Shillaker <554768+Shillaker@users.noreply.github.com> --------- Co-authored-by: Simon Shillaker <554768+Shillaker@users.noreply.github.com>
- Loading branch information
Showing
7 changed files
with
126 additions
and
19 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
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,29 @@ | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
# Doing a conditional import avoids the need to install the library | ||
# when deploying the function | ||
from scaleway_functions_python.framework.v1.hints import Context, Event, Response | ||
|
||
|
||
def hello(_event: "Event", _context: "Context") -> "Response": | ||
"""Say hello!""" | ||
return {"body": "hello"} | ||
|
||
|
||
def world(_event: "Event", _context: "Context") -> "Response": | ||
"""Say world!""" | ||
return {"body": "world"} | ||
|
||
|
||
if __name__ == "__main__": | ||
from scaleway_functions_python import local | ||
|
||
server = local.LocalFunctionServer() | ||
server.add_handler(hello) | ||
server.add_handler(world) | ||
server.serve(port=8080) | ||
|
||
# Functions can be queried with: | ||
# curl localhost:8080/hello | ||
# curl localhost:8080/world |
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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from . import local as local | ||
from .framework import v1 as v1 | ||
from .local.serving import LocalFunctionServer as LocalFunctionServer | ||
from .local.serving import serve_handler as serve_handler |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
from .serving import LocalFunctionServer as LocalFunctionServer | ||
from .serving import serve_handler as serve_handler |
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
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