44Custom Sockets in Syncano
55=========================
66
7- ``Syncano `` gives its users an ability to create Custom Sockets. What it means is that users can define
8- a very specific endpoints in their Syncano application, and use them exactly like they would any other Syncano
7+ ``Syncano `` gives its users the ability to create Custom Sockets. What this means is that users can define very specific
8+ endpoints in their Syncano application, and use them exactly like they would any other Syncano
99module (Classes, Scripts, etc), using standard API calls.
10- Currently, Custom Sockets allow only one dependency - Scripts. It means that under the hood,
11- each API call executes a Script, and result of this execution is returned as a result of the
10+ Currently, Custom Sockets allow only one dependency - Scripts. Under the hood,
11+ each API call executes a Script, and the result of this execution is returned as a result of the
1212API call.
1313
14- Creating a custom socket
14+ Creating a custom Socket
1515------------------------
1616
17- To create a custom socket follow these steps::
17+ To create a custom Socket follow these steps::
1818
1919 import syncano
2020 from syncano.models import CustomSocket, Endpoint, ScriptCall, ScriptDependency, RuntimeChoices
2121 from syncano.connection import Connection
2222
23- # 1. Initialize a custom socket .
23+ # 1. Initialize a custom Socket .
2424 custom_socket = CustomSocket(name='my_custom_socket') # this will create an object in place (do API call)
2525
2626 # 2. Define endpoints.
@@ -29,28 +29,28 @@ To create a custom socket follow these steps::
2929 my_endpoint.add_call(ScriptCall(name='another_custom_script'), methods=['POST'])
3030
3131 # What happened here:
32- # - We defined a new endpoint, that will be visible under `my_endpoint` name.
32+ # - We defined a new endpoint that will be visible under the name `my_endpoint`
3333 # - You will be able to call this endpoint (execute attached `call`),
34- # by sending a reuqest , using any defined method to following API route:
34+ # by sending a request , using any defined method to the following API route:
3535 # <host>://<api_version>/instances/<instance_name>/endpoints/sockets/my_endpoint/
36- # - To get details on that endpoint, you need to send a GET request to following API route:
36+ # - To get details for that endpoint, you need to send a GET request to following API route:
3737 # <host>://<api_version>/instances/<instance_name>/sockets/my_custom_socket/endpoints/my_endpoint/
3838 #
39- # Following example above - we defined two calls on our endpoint.
40- # First one means that using GET method will call the `custom_script` script ,
41- # and second one means that using POST method will call the `another_custom_script` script .
42- # At the moment, only scripts are available as endpoint calls.
39+ # Following the example above - we defined two calls on our endpoint with the `add_call` method
40+ # The first one means that using a GET method will call the `custom_script` Script ,
41+ # and second one means that using a POST method will call the `another_custom_script` Script .
42+ # At the moment, only Scripts are available as endpoint calls.
4343 #
44- # As a general rule - to get endpoints details (but not call them), use following API route:
44+ # As a general rule - to get endpoint details (but not call them), use following API route:
4545 # <host>://<api_version>/instances/<instance_name>/sockets/my_custom_socket/endpoints/<endpoint>/
46- # and to run your endpoints (e.g. execute Script connected to them( , use following API route:
46+ # and to run your endpoints (e.g. execute Script connected to them) , use following API route:
4747 # <host>://<api_version>/instances/<instance_name>/endpoints/sockets/<endpoint>/
4848
4949 # 3. After creation of the endpoint, add it to your custom_socket.
5050 custom_socket.add_endpoint(my_endpoint)
5151
5252 # 4. Define dependency.
53- # 4.1 Using a new script - define a new source code.
53+ # 4.1 Using a new Script - define a new source code.
5454 custom_socket.add_dependency(
5555 ScriptDependency(
5656 Script(
@@ -60,7 +60,7 @@ To create a custom socket follow these steps::
6060 name='custom_script'
6161 )
6262 )
63- # 4.2 Using an existing script .
63+ # 4.2 Using an existing Script .
6464 another_custom_script = Script.please.get(id=2)
6565 custom_socket.add_dependency(
6666 ScriptDependency(
@@ -78,19 +78,19 @@ To create a custom socket follow these steps::
7878 # 5. Publish custom_socket.
7979 custom_socket.publish() # this will make an API call and create a script;
8080
81- Sometimes, it's needed to set up the environment for the custom socket .
82- It's possible to check the custom socket status::
81+ It may take some time to set up the Socket, so you can check the status .
82+ It's possible to check the custom Socket status::
8383
8484 # Reload will refresh object using Syncano API.
8585 custom_socket.reload()
8686 print(custom_socket.status)
8787 # and
8888 print(custom_socket.status_info)
8989
90- Updating the custom socket
90+ Updating the custom Socket
9191--------------------------
9292
93- To update custom socket , use::
93+ To update custom Socket , use::
9494
9595 custom_socket = CustomSocket.please.get(name='my_custom_socket')
9696
@@ -109,19 +109,19 @@ To update custom socket, use::
109109 custom_socket.update()
110110
111111
112- Running custom socket
112+ Running custom Socket
113113-------------------------
114114
115- To run a custom socket use::
115+ To run a custom Socket use::
116116
117- # this will run `my_endpoint` - and call `custom_script` ( using GET method) ;
117+ # this will run `my_endpoint` - and call `custom_script` using GET method;
118118 result = custom_socket.run(method='GET', endpoint_name='my_endpoint')
119119
120120
121- Read all endpoints in a custom socket
121+ Read all endpoints in a custom Socket
122122-----------------------------------
123123
124- To get the all defined endpoints in a custom socket run::
124+ To get the all defined endpoints in a custom Socket run::
125125
126126 endpoints = custom_socket.get_endpoints()
127127
@@ -140,7 +140,7 @@ Data will be passed to the API call in the request body.
140140Read all endpoints
141141------------------
142142
143- To get all endpoints that are defined in all custom sockets ::
143+ To get all endpoints that are defined in all custom Sockets ::
144144
145145 socket_endpoint_list = SocketEndpoint.get_all_endpoints()
146146
@@ -155,15 +155,15 @@ and now run it::
155155 # or:
156156 endpoint.run(method='POST', data={'custom_data': 1})
157157
158- Custom sockets endpoints
158+ Custom Sockets endpoints
159159------------------------
160160
161- Each custom socket requires a definition of at least one endpoint. This endpoint is defined by name and
162- a list of calls. Each call is defined by its name and a list of methods. Name is used in identification for dependency, eg.
163- if it's equal to 'my_script' - the ScriptEndpoint with name 'my_script' will be used
164- (if it exists and Script source and passed runtime match) -- otherwise a new one will be created.
165- There's a special wildcard method: `methods=['*'] ` - it means that any request with
166- any method will be executed in this endpoint .
161+ Each custom socket requires defining at least one endpoint. This endpoint is defined by name and
162+ a list of calls. Each call is defined by its name and a list of methods. ` name ` is used as an
163+ identification for the dependency, eg. if ` name ` is equal to 'my_script' - the ScriptEndpoint with name 'my_script'
164+ will be used (if it exists and Script source and passed runtime match) -- otherwise a new one will be created.
165+ There's a special wildcard method: `methods=['*'] ` - this allows you to execute the provided custom Socket
166+ with any request method (GET, POST, PATCH, etc.) .
167167
168168To add an endpoint to a chosen custom_socket use::
169169
@@ -173,14 +173,14 @@ To add an endpoint to a chosen custom_socket use::
173173
174174 custom_socket.add_endpoint(my_endpoint)
175175
176- Custom socket dependency
176+ Custom Socket dependency
177177------------------------
178178
179179Each custom socket has a dependency -- meta information for an endpoint: which resource
180- should be used to return the API call results. These dependencies are bound to the endpoints call objects .
180+ should be used to return the API call results. These dependencies are bound to the endpoints call object .
181181Currently the only supported dependency is a Script.
182182
183- **Using new script **
183+ **Using new Script **
184184
185185::
186186
@@ -195,7 +195,7 @@ Currently the only supported dependency is a Script.
195195 )
196196
197197
198- **Using defined script **
198+ **Using defined Script **
199199
200200::
201201
@@ -207,7 +207,7 @@ Currently the only supported dependency is a Script.
207207 )
208208 )
209209
210- **Using defined script endpoint **
210+ **Using defined Script endpoint **
211211
212212::
213213
@@ -216,31 +216,31 @@ Currently the only supported dependency is a Script.
216216 script_endpoint
217217 )
218218
219- You can overwrite the name in the following way::
219+ You can overwrite the Script name in the following way::
220220
221221 script_endpoint = ScriptEndpoint.please.get(name='script_endpoint_name')
222222 custom_socket.add_dependency(
223223 script_endpoint,
224224 name='custom_name'
225225 )
226226
227- Custom socket recheck
227+ Custom Socket recheck
228228---------------------
229229
230- The creation of the socket can fail - this can happen, e.g. when an endpoint name is already taken by another
231- custom socket . To check the statuses use::
230+ The creation of a Socket can fail - this can happen, for example, when an endpoint name is already taken by another
231+ custom Socket . To check the creation status use::
232232
233233 print(custom_socket.status)
234234 print(custom_socket.status_info)
235235
236- There is a possibility to re-check socket - this mean that if conditions are met - the socket endpoints and dependencies
237- will be checked - and if some of them are missing (e.g. some were deleted by mistake), they will be created again.
238- If the endpoints and dependencies do not meet the criteria - an error will be returned in the status field.
236+ You can also re-check a Socket. This mean that all dependencies will be checked - if some of them are missing
237+ (e.g. some were deleted by mistake), they will be created again. If the endpoints and dependencies do not meet
238+ the criteria - an error will be returned in the status field.
239239
240- Custom socket - raw format
240+ Custom Socket - raw format
241241--------------------------
242242
243- If you prefer raw JSON format for creating sockets, you can resort to use it in python library as well ::::
243+ If you prefer raw JSON format for creating Sockets, the Python library allows you to do so ::::
244244
245245 CustomSocket.please.create(
246246 name='my_custom_socket_3',
@@ -262,4 +262,4 @@ If you prefer raw JSON format for creating sockets, you can resort to use it in
262262 ]
263263 )
264264
265- The disadvantage of this method is that internal structure of the JSON file must be known by developer.
265+ The disadvantage of this method is that the internal structure of the JSON file must be known by the developer.
0 commit comments