8000 Updated routing docs · python-microservices/pyms@64d150b · GitHub
[go: up one dir, main page]

Skip to content

Commit 64d150b

Browse files
committed
Updated routing docs
1 parent a158404 commit 64d150b

File tree

1 file changed

+53
-29
lines changed

1 file changed

+53
-29
lines changed

docs/routing.md

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,34 @@
11
# Routing
2+
With PyMS you can extend the Microservice with [Connexion](https://github.com/zalando/connexion) and [swagger-ui](https://github.com/sveint/flask-swagger-ui).
3+
4+
To use connexion, you must set in your config.yaml this:
5+
```yaml
6+
pyms:
7+
services:
8+
[...]
9+
swagger:
10+
path: ""
11+
file: "swagger.yaml"
12+
config:
13+
[...]
14+
```
15+
16+
If you want to know more about configure swagger service, see [Service section](services.md).
17+
18+
Now, you can create a `swagger.yaml` file with [OpenAPI Specification](https://swagger.io/specification/).
19+
20+
## Routing to files
221

322
This section is equal from [Zalando Connexion](https://github.com/zalando/connexion#automatic-routing), because PyMS use
4-
this library to route endpoints to functions
23+
this library to route endpoints to functions:
524

625
**Explicit Routing**:
726

827
```yaml
928
paths:
10-
/hello_world:
11-
post:
12-
operationId: myapp.api.hello_world
29+
/hello_world:
30+
post:
31+
operationId: myapp.api.hello_world
1332
```
1433

1534
If you provide this path in your specification POST requests to
@@ -19,11 +38,11 @@ If you provide this path in your specification POST requests to
1938
operation definition, making ``operationId`` relative:
2039

2140
```yaml
22-
paths:
23-
/hello_world:
24-
post:
25-
x-swagger-router-controller: myapp.api
26-
operationId: hello_world
41+
paths:
42+
/hello_world:
43+
post:
44+
x-swagger-router-controller: myapp.api
45+
operationId: hello_world
2746
```
2847

2948
Keep in mind that Connexion follows how `HTTP methods work in Flask`_ and therefore HEAD requests will be handled by the ``operationId`` specified under GET in the specification. If both methods are supported, ``connexion.request.method`` can be used to determine which request was made.
@@ -42,25 +61,24 @@ ms = Microservice(path=__file__)
4261
```
4362

4463
```yaml
45-
paths:
46-
/:
47-
get:
48-
# Implied operationId: api.get
49-
/foo:
50-
get:
51-
# Implied operationId: api.foo.search
52-
post:
53-
# Implied operationId: api.foo.post
54-
55-
'/foo/{id}':
56-
get:
57-
# Implied operationId: api.foo.get
58-
put:
59-
# Implied operationId: api.foo.put
60-
copy:
61-
# Implied operationId: api.foo.copy
62-
delete:
63-
# Implied operationId: api.foo.delete
64+
paths:
65+
/:
66+
get:
67+
# Implied operationId: api.get
68+
/foo:
69+
get:
70+
# Implied operationId: api.foo.search
71+
post:
72+
# Implied operationId: api.foo.post
73+
'/foo/{id}':
74+
get:
75+
# Implied operationId: api.foo.get
76+
put:
77+
# Implied operationId: api.foo.put
78+
copy:
79+
# Implied operationId: api.foo.copy
80+
delete:
81+
# Implied operationId: api.foo.delete
6482
```
6583

6684
``RestyResolver`` will give precedence to any ``operationId`` encountered in the specification. It will also respect
@@ -99,4 +117,10 @@ def foo_get(message):
99117

100118
In this example, Connexion automatically recognizes that your view
101119
function expects an argument named ``message`` and assigns the value
102-
of the endpoint parameter ``message`` to your view function.
120+
of the endpoint parameter ``message`` to your view function.
121+
122+
# Examples of routing
123+
124+
You can see how structure a project or OpenAPI Specification in
125+
[PyMS examples](https://github.com/python-microservices/pyms/tree/master/examples/microservice_swagger) or in
126+
[Microservice Scaffold](https://github.com/python-microservices/microservices-scaffold)

0 commit comments

Comments
 (0)
0