Skip to content

Commit 3ac9fd0

Browse files
authored
docs: add gateway documentation (#77)
1 parent 28001a9 commit 3ac9fd0

File tree

7 files changed

+95
-50
lines changed

7 files changed

+95
-50
lines changed

docs/source/configuring.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ When deploying, the `scw-serverless` CLI will look for a Serverless instance in
2424
})
2525
2626
.. autoclass:: scw_serverless.app.Serverless
27-
:members: func
27+
:members: func, get, post, put
2828

2929
Functions
3030
---------
3131

32-
To configure your serverless functions, you can provide keyword arguments to the decorators. The Function name that will appear in Scaleway console will be the name of your function's handler.
32+
To configure your serverless functions, you can provide keyword arguments to the decorators. The Function name that will appear in the Scaleway console will be the name of your function's handler.
3333

3434
.. autoclass:: scw_serverless.config.function.FunctionKwargs
3535

docs/source/deploying.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Generate
1818
--------
1919

2020
Generators will generate configuration files to use with other deployment tools.
21-
Currently, you can generate either a `serverless` or `terraform` configuration file. This can useful to integrate with your existing tooling.
21+
Currently, you can generate either a `serverless` or `terraform` configuration file. This can be useful to integrate with your existing tooling.
2222

2323
Config file generation is done with the `generate` command:
2424

docs/source/gateway.rst

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,45 @@
11
API Gateway
22
===========
33

4-
.. warning:: Not yet implemented.
4+
The framework provides support for routed functions via a Gateway container that can be deployed separately.
5+
For more information, please consult the documentation on the `Serverless Gateway repository`_
56

6-
Routed functions
7-
^^^^^^^^^^^^^^^^
7+
Quickstart
8+
^^^^^^^^^^
89

9-
.. autodocs:: scw_serverless.app.Serverless.func
10+
* Write your routed function
11+
12+
.. code-block:: python
13+
14+
# In app.py
15+
16+
app = Serverless("example")
17+
18+
app.get("/hello-gateway", memory_limit= 256)
19+
def handler(event, context):
20+
return {"body": "Hello from Gateway!"}
21+
22+
* Clone the `Serverless Gateway repository`_
23+
* Follow the steps in README to deploy your API Gateway
24+
* Create an API token for the Gateway. In the gateway repository, you can use a make command:
25+
26+
.. code-block:: console
27+
28+
make generate-token
29+
export TOKEN=$(make get-token)
30+
export GATEWAY_HOST=$(make gateway-host)
31+
32+
* Finally, use `scw-serverless` to deploy your function and set up the route on your Gateway:
33+
34+
.. code-block:: console
35+
36+
scw-serverless deploy app.py --gateway-url https://${GATEWAY_HOST} --gateway-api-key ${TOKEN}
37+
38+
* You can now call your function via your Gateway!
39+
40+
.. code-block:: console
41+
42+
$ curl https://${GATEWAY_HOST}/hello-gateway
43+
> Hello from Gateway!
44+
45+
.. _Serverless Gateway Repository: https://github.com/scaleway/serverless-gateway

poetry.lock

Lines changed: 37 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ boto3 = "^1.26.97"
5757
optional = true
5858

5959
[tool.poetry.group.doc.dependencies]
60-
myst_parser = ">=0.18.1,<1.1.0"
61-
sphinx = "^5.3.0"
62-
sphinx_rtd_theme = "^1.1.1"
60+
myst_parser = "^1.0.0"
61+
sphinx = "^6.1.0"
62+
sphinx_rtd_theme = "^1.2.0"
6363

6464
[tool.pytest.ini_options]
6565
filterwarnings = [

scw_serverless/app.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ def get(self, url: str, **kwargs: Unpack[FunctionKwargs]) -> Callable:
104104
.. note::
105105
106106
Requires an API gateway
107+
108+
For more information, please consult the :doc:`gateway` page.
107109
"""
108110
kwargs |= {"relative_url": url, "http_methods": [HTTPMethod.GET]}
109111
return self.func(**kwargs)
@@ -114,8 +116,9 @@ def post(self, url: str, **kwargs: Unpack[FunctionKwargs]) -> Callable:
114116
:param url: relative url to trigger the function
115117
116118
.. note::
117-
118119
Requires an API gateway
120+
121+
For more information, please consult the :doc:`gateway` page.
119122
"""
120123
kwargs |= {"relative_url": url, "http_methods": [HTTPMethod.POST]}
121124
return self.func(**kwargs)
@@ -128,6 +131,8 @@ def put(self, url: str, **kwargs: Unpack[FunctionKwargs]) -> Callable:
128131
.. note::
129132
130133
Requires an API gateway
134+
135+
For more information, please consult the :doc:`gateway` page.
131136
"""
132137
kwargs |= {"relative_url": url, "http_methods": [HTTPMethod.PUT]}
133138
return self.func(**kwargs)
@@ -140,6 +145,8 @@ def delete(self, url: str, **kwargs: Unpack[FunctionKwargs]) -> Callable:
140145
.. note::
141146
142147
Requires an API gateway
148+
149+
For more information, please consult the :doc:`gateway` page.
143150
"""
144151
kwargs |= {"relative_url": url, "http_methods": [HTTPMethod.DELETE]}
145152
return self.func(**kwargs)
@@ -152,6 +159,8 @@ def patch(self, url: str, **kwargs: Unpack[FunctionKwargs]) -> Callable:
152159
.. note::
153160
154161
Requires an API gateway
162+
163+
For more information, please consult the :doc:`gateway` page.
155164
"""
156165
kwargs |= {"relative_url": url, "http_methods": [HTTPMethod.PATCH]}
157166
return self.func(**kwargs)

scw_serverless/config/function.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ class FunctionKwargs(TypedDict, total=False):
4646
4747
.. seealso::
4848
49-
Scaleway Developers Documentation
50-
https://developers.scaleway.com/en/products/functions/api/#create-a-function
49+
`Scaleway Developers Documentation
50+
<https://developers.scaleway.com/en/products/functions/api/#create-a-function>`_
5151
"""
5252

5353
env: dict[str, str]

0 commit comments

Comments
 (0)