Skip to content

Commit 6b5bc4b

Browse files
authored
Update docs, How To contribute, Create your own service (#176)
1 parent 73b5436 commit 6b5bc4b

File tree

4 files changed

+121
-56
lines changed

4 files changed

+121
-56
lines changed

CONTRIBUTING.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,60 @@ This project use MkDocs
9494
mkdocs.yml # The configuration file.
9595
docs/
9696
index.md # The documentation homepage.
97-
... # Other markdown pages, images and other files.
97+
... # Other markdown pages, images and other files.
98+
99+
## Tutorial: Create your own service
100+
101+
* First, you must create a file with the name of your service inside of `pyms.flask.service`, for example,
102+
"myawesomesrv":
103+
104+
pyms/flask/services/myawesomesrv.py
105+
```python
106+
from pyms.flask.services.driver import DriverService
107+
108+
109+
class Service(DriverService):
110+
service = "myawesomesrv"
111+
default_values = {
112+
"myvalue": 0,
113+
"myvalue2": 1
114+
}
115+
```
116+
117+
* Now, you can configure your service from `config.yml`
118+
```yaml
119+
pyms:
120+
config:
121+
myawesomesrv:
122+
myvalue: 5
123+
```
124+
125+
* Your service will be instanced inside the `ms` object in `flask.current_app` object. For example, with the last config,
126+
you could print the folowing code:
127+
128+
```python
129+
from flask import jsonify, current_app
130+
131+
from pyms.flask.app import Microservice
132+
133+
ms = Microservice(service="my-minimal-microservice", path=__file__)
134+
app = ms.create_app()
135+
136+
137+
@app.route("/")
138+
def example():
139+
return jsonify({
140+
"myvalue": current_app.ms.myawesomesrv.myvalue,
141+
"myvalue2": current_app.ms.myawesomesrv.myvalue2
142+
})
143+
144+
145+
if __name__ == '__main__':
146+
app.run()
147+
```
148+
149+
This would be the output in `http://localhost:5000/`:
150+
151+
```json
152+
{"myvalue": 5, "myvalue2": 1}
153+
```

docs/services.md

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -132,58 +132,6 @@ pyms:
132132
This will add the endpoint `/metrics` to your microservice, which will expose
133133
the metrics.
134134

135-
## How to contrib: create your own service
135+
## How to contrib:
136136

137-
* First, you must create a file with the name of your service inside of `pyms.flask.service`, for example,
138-
"myawesomesrv":
139-
140-
pyms/flask/services/myawesomesrv.py
141-
```python
142-
from pyms.flask.services.driver import DriverService
143-
144-
145-
class Service(DriverService):
146-
service = "myawesomesrv"
147-
default_values = {
148-
"myvalue": 0,
149-
"myvalue2": 1
150-
}
151-
```
152-
153-
* Now, you can configure your service from `config.yml`
154-
```yaml
155-
pyms:
156-
config:
157-
myawesomesrv:
158-
myvalue: 5
159-
```
160-
161-
* Your service will be instanced inside the `ms` object in `flask.current_app` object. For example, with the last config,
162-
you could print the folowing code:
163-
164-
```python
165-
from flask import jsonify, current_app
166-
167-
from pyms.flask.app import Microservice
168-
169-
ms = Microservice(service="my-minimal-microservice", path=__file__)
170-
app = ms.create_app()
171-
172-
173-
@app.route("/")
174-
def example():
175-
return jsonify({
176-
"myvalue": current_app.ms.myawesomesrv.myvalue,
177-
"myvalue2": current_app.ms.myawesomesrv.myvalue2
178-
})
179-
180-
181-
if __name__ == '__main__':
182-
app.run()
183-
```
184-
185-
This would be the output in `http://localhost:5000/`:
186-
187-
```json
188-
{"myvalue": 5, "myvalue2": 1}
189-
```
137+
[See tutorial](tutorial_create_services.md)

docs/tutorial_create_services.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Tutorial 2: How To contribute, Create your own service
2+
3+
* First, you must create a file with the name of your service inside of `pyms.flask.service`, for example,
4+
"myawesomesrv":
5+
6+
pyms/flask/services/myawesomesrv.py
7+
```python
8+
from pyms.flask.services.driver import DriverService
9+
10+
11+
class Service(DriverService):
12+
service = "myawesomesrv"
13+
default_values = {
14+
"myvalue": 0,
15+
"myvalue2": 1
16+
}
17+
```
18+
19+
* Now, you can configure your service from `config.yml`
20+
```yaml
21+
pyms:
22+
config:
23+
myawesomesrv:
24+
myvalue: 5
25+
```
26+
27+
* Your service will be instanced inside the `ms` object in `flask.current_app` object. For example, with the last config,
28+
you could print the folowing code:
29+
30+
```python
31+
from flask import jsonify, current_app
32+
33+
from pyms.flask.app import Microservice
34+
35+
ms = Microservice(service="my-minimal-microservice", path=__file__)
36+
app = ms.create_app()
37+
38+
39+
@app.route("/")
40+
def example():
41+
return jsonify({
42+
"myvalue": current_app.ms.myawesomesrv.myvalue,
43+
"myvalue2": current_app.ms.myawesomesrv.myvalue2
44+
})
45+
46+
47+
if __name__ == '__main__':
48+
app.run()
49+
```
50+
51+
This would be the output in `http://localhost:5000/`:
52+
53+
```json
54+
{"myvalue": 5, "myvalue2": 1}
55+
```

docs/tutorials.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,11 @@
33
This section shows tutorials to avanced use of PyMS. See [Examples](examples.md) for simple tutorials
44

55
## Tutorial 1: Propagate Traces
6+
With this tutorial you can solve the problem of [distributed tracing](https://microservices.io/patterns/observability/distributed-tracing.html)
67

7-
[Examples](tutorial_propagate_traces.md)
8+
[See tutorial](tutorial_propagate_traces.md)
9+
10+
11+
## Tutorial 2: How To contribute, Create your own service
12+
13+
[See tutorial](tutorial_create_services.md)

0 commit comments

Comments
 (0)