@@ -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+ ` ` `
0 commit comments