You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/routing.md
+53-29Lines changed: 53 additions & 29 deletions
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,34 @@
1
1
# 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
2
21
3
22
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:
5
24
6
25
**Explicit Routing**:
7
26
8
27
```yaml
9
28
paths:
10
-
/hello_world:
11
-
post:
12
-
operationId: myapp.api.hello_world
29
+
/hello_world:
30
+
post:
31
+
operationId: myapp.api.hello_world
13
32
```
14
33
15
34
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
19
38
operation definition, making ``operationId`` relative:
20
39
21
40
```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
27
46
```
28
47
29
48
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__)
42
61
```
43
62
44
63
```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
64
82
```
65
83
66
84
``RestyResolver`` will give precedence to any ``operationId`` encountered in the specification. It will also respect
@@ -99,4 +117,10 @@ def foo_get(message):
99
117
100
118
In this example, Connexion automatically recognizes that your view
101
119
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
0 commit comments