Skip to content

Commit 6c296c0

Browse files
committed
Merge branch 'task/updated-documentation'
2 parents ddcb131 + eddeebf commit 6c296c0

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

docs/services.md

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,57 @@ pyms:
5454
This will add the endpoint `/metrics` to your microservice, which will expose
5555
the metrics.
5656

57-
## How to contrib: create your own service:
57+
## How to contrib: create your own service
5858

59-
TODO
59+
* First, you must create a file with the name of your service inside of `pyms.flask.service`, for example,
60+
"myawesomesrv":
61+
62+
pyms/flask/services/myawesomesrv.py
63+
```python
64+
from pyms.flask.services.driver import DriverService
65+
66+
67+
class Service(DriverService):
68+
service = "myawesomesrv"
69+
default_values = {
70+
"myvalue": 0,
71+
"myvalue2": 1
72+
}
73+
```
74+
75+
* Now, you can configure your service from `config.yml`
76+
```yaml
77+
pyms:
78+
myawesomesrv:
79+
myvalue: 5
80+
```
81+
82+
* Your service will be setted inside `ms` object in `flask.current_app` objetct. for example, with the last config,
83+
you can print the next code:
84+
85+
```python
86+
from flask import jsonify, current_app
87+
88+
from pyms.flask.app import Microservice
89+
90+
ms = Microservice(service="my-minimal-microservice", path=__file__)
91+
app = ms.create_app()
92+
93+
94+
@app.route("/")
95+
def example():
96+
return jsonify({
97+
"myvalue": current_app.ms.myawesomesrv.myvalue,
98+
"myvalue2": current_app.ms.myawesomesrv.myvalue2
99+
})
100+
101+
102+
if __name__ == '__main__':
103+
app.run()
104+
```
105+
106+
This output in `http://localhost:5000/`:
107+
108+
```json
109+
{"myvalue": 5, "myvalue2": 1}
110+
```

0 commit comments

Comments
 (0)