File: api_rest.rst

package info (click to toggle)
pywps 4.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,016 kB
  • sloc: python: 8,846; xml: 723; makefile: 106
file content (407 lines) | stat: -rw-r--r-- 10,346 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
.. _api_rest:

###################
PyWPS Rest API Doc
###################

Since version 4.5, PyWPS includes an experimental implementation of the novel OGC API.
This standard defines the OGC API - Processes API standard.
This standard builds on the OGC Web Processing Service (WPS) 2.0 Standard
and defines the processing interface to communicate over a RESTful protocol using JSON encodings.

For more details about the standard please refer to https://github.com/opengeospatial/ogcapi-processes

Defining the input/output format (JSON or XML)
================================================

WPS 1.0 standard defines input and outputs in XML format.
OGC API - Processes: rest-api, json.
PyWPS >= 4.5 allows inputs and outputs to be in both XML and JSON formats.

The default format (mimetype) of the input/output is determinate by the URL:

* Default XML - if the url starts with `/wps`
* Default JSON - if the url starts with `/jobs` or `/processes`

Please refer to `app.basic.parse_http_url` for full details about those defaults.


GET request:
-------------

The default mimetype (output format) can be set by adding `&f=json` or `&f=xml` parameter.

GET GetCapabilities Request URL:

.. code-block:: json

    http://localhost:5000/processes/?service=WPS
    http://localhost:5000/wps/?request=GetCapabilities&service=WPS&f=json

GET GetCapabilities Response:

.. code-block:: json

    {
      "pywps_version": "4.5.0",
      "version": "1.0.0",
      "title": "PyWPS WPS server",
      "abstract": "PyWPS WPS server server.",
      "keywords": [
        "WPS",
        "PyWPS",
      ],
      "provider": {
        "name": "PyWPS Development team",
        "site": "https://github.com/geopython/pywps-flask",
      },
      "serviceurl": "http://localhost:5000/wps",
      "languages": [
        "en-US"
      ],
      "language": "en-US",
      "processes": [
        {
          "class": "processes.sayhello:SayHello",
          "uuid": "None",
          "workdir": null,
          "version": "1.3.3.8",
          "identifier": "say_hello",
          "title": "Process Say Hello",
          "abstract": "Returns a literal string output with Hello plus the inputed name",
          "keywords": [],
          "metadata": [],
          "inputs": [
            {
              "identifier": "name",
              "title": "Input name",
              "abstract": "",
              "keywords": [],
              "metadata": [],
              "type": "literal",
              "data_type": "string",
              "workdir": null,
              "allowed_values": [],
              "any_value": false,
              "mode": 1,
              "min_occurs": 1,
              "max_occurs": 1,
              "translations": null,
              "data": "World"
            }
          ],
          "outputs": [
            {
              "identifier": "output",
              "title": "Output response",
              "abstract": "",
              "keywords": [],
              "data": null,
              "data_type": "string",
              "type": "literal",
              "uoms": [],
              "translations": null
            }
          ],
          "store_supported": "true",
          "status_supported": "true",
          "profile": [],
          "translations": null
        }
      ]
    }

GET DescribeProcess Request URL:

.. code-block:: json

    http://localhost:5000/processes/say_hello?service=WPS
    http://localhost:5000/wps/?request=DescribeProcess&service=WPS&identifier=say_hello&version=1.0.0&f=json

GET DescribeProcess Response:

.. code-block:: json

    {
      "pywps_version": "4.5.0",
      "processes": [
        {
          "class": "processes.sayhello:SayHello",
          "uuid": "None",
          "workdir": null,
          "version": "1.3.3.8",
          "identifier": "say_hello",
          "title": "Process Say Hello",
          "abstract": "Returns a literal string output with Hello plus the inputed name",
          "keywords": [],
          "metadata": [],
          "inputs": [
            {
              "identifier": "name",
              "title": "Input name",
              "abstract": "",
              "keywords": [],
              "metadata": [],
              "type": "literal",
              "data_type": "string",
              "workdir": null,
              "allowed_values": [],
              "any_value": false,
              "mode": 1,
              "min_occurs": 1,
              "max_occurs": 1,
              "translations": null,
              "data": "World"
            }
          ],
          "outputs": [
            {
              "identifier": "output",
              "title": "Output response",
              "abstract": "",
              "keywords": [],
              "data": null,
              "data_type": "string",
              "type": "literal",
              "uoms": [],
              "translations": null
            }
          ],
          "store_supported": "true",
          "status_supported": "true",
          "profile": [],
          "translations": null
        }
      ],
      "language": "en-US"
    }

GET Execute Request URL:

.. code-block:: json

    http://localhost:5000/wps?/service=wps&version=1.0.0&request=execute&Identifier=say_hello&storeExecuteResponse=true&DataInputs=name=Dude&f=json

GET Execute Response:

.. code-block:: json

    {
        "status": {
            "status": "succeeded",
            "time": "2021-06-15T14:19:28Z",
            "percent_done": "100",
            "message": "PyWPS Process Process Say Hello finished"
        },
        "outputs": {
            "output": "Hello Dude"
        }
    }

GET Execute Request URL (Raw output):

.. code-block:: json

    http://localhost:5000/wps?/service=wps&version=1.0.0&request=execute&Identifier=say_hello&storeExecuteResponse=true&DataInputs=name=Dude&RawDataOutput=output

GET Execute Response:

.. code-block:: json

    Hello Dude


POST request:
---------------

The default mimetype (input and output formats) can be changed by setting the following headers
of a POST request to one following values `text/xml` or `application/json`:

    * `Content-Type` (format of the input)
    * `Accept` (format of the output)

Example of a `Say Hello` POST request:

POST Execute Request URL:

.. code-block:: json

    http://localhost:5000/jobs

POST Execute Request Body:

.. code-block:: json

    {
        "identifier": "say_hello",
        "inputs": {
            "name": "Dude"
        }
    }

POST Execute Response:

.. code-block:: json

    {
        "status": {
            "status": "succeeded",
            "time": "2021-06-15T14:19:28Z",
            "percent_done": "100",
            "message": "PyWPS Process Process Say Hello finished"
        },
        "outputs": {
            "output": "Hello Dude"
        }
    }


Example of a `Say Hello` POST request with raw output:

POST Execute Request Body:

.. code-block:: json

    {
        "identifier": "say_hello",
        "outputs": "output",
        "inputs": {
            "name": "Dude"
        }
    }


POST Execute Response:

.. code-block:: json

    Hello Dude

Alternatively, the `identifier` and optionally the raw output name can be encoded in the Request URL:

POST Execute Request URL (with `identifier`):

.. code-block:: json

    http://localhost:5000/jobs/say_hello

POST Execute Request Body:

.. code-block:: json

    {
        "name": "Dude"
    }

POST Execute Response:

.. code-block:: json

    {
        "status": {
            "status": "succeeded",
            "time": "2021-06-15T14:19:28Z",
            "percent_done": "100",
            "message": "PyWPS Process Process Say Hello finished"
        },
        "outputs": {
            "output": "Hello Dude"
        }
    }

POST Execute Request URL (with `identifier` and output name):

.. code-block:: json

    http://localhost:5000/jobs/say_hello/output

POST Execute Request Body:

.. code-block:: json

    {
        "name": "Dude"
    }

POST Execute Response:

.. code-block:: json

    Hello Dude


Example for a reference input:

.. code-block:: json

    "raster": {
        "type": "reference",
        "href": "file:./path/to/data/data.tif"
    }

Example for a BoundingBox input:
(bbox default axis order is yx (EPSG:4326), i.e. miny, minx, maxy, maxx)

.. code-block:: json

    "extent": {
        "type": "bbox",
        "bbox": [32, 34.7, 32.1, 34.8]
    }


Example for a ComplexInput input:
(the data is a standard GeoJSON)

.. code-block:: json

    "cutline": {
        "type": "complex",
        "data": {
            "type": "FeatureCollection",
            "name": "Center",
            "crs": {
                "type": "name",
                "properties": {
                    "name": "urn:ogc:def:crs:OGC:1.3:CRS84"
                }
            },
            "features": [
                {
                    "type": "Feature",
                    "properties": {},
                    "geometry": {
                        "type": "Polygon",
                        "coordinates": [
                            [
                                [
                                    34.76844787397541,
                                    32.07247233606565
                                ],
                                [
                                    34.78658619364754,
                                    32.07260143442631
                                ],
                                [
                                    34.77780750512295,
                                    32.09532274590172
                                ],
                                [
                                    34.76844787397541,
                                    32.07247233606565
                                ]
                            ]
                        ]
                    }
                }
            ]
        }
    }


The examples above show some `Literal`, 'Complex', `BoundingBox` inputs.
Internally, PyWPS always keeps the inputs in JSON formats (also in previous versions)
So potentially all input types that are supported in XML should also be supported in JSON,
though only a small subset of them were tested in this preliminary implementation.

Multiple inputs for the same parameter can be passed by using a list as the parameter value.