pacificclimate / climate-explorer-backend

3 stars 1 forks source link

Accept POST requests #229

Closed corviday closed 7 months ago

corviday commented 7 months ago

Updates the backend to accept HTTP POST requests in addition to HTTP GET. This is a straightforward update thanks to Flask's handy request.values attribute, which contains all parameters supplied either in the URL of a POST or the body of a GET, allowing the request methods to be treated identically.

The goal here is to be able to accept longer area strings, especially from user-selected regions, such as when a user clicks on a point in a flow network to select all grid squares upstream of that point. One notable example of selecting an upstream area along the FRASER river results in an area string ten thousand characters long, too long to send in a URL.

resolves #227

corviday commented 7 months ago

A demo is available at https://services.pacificclimate.org/dev/pcex/api/

Sample curl commands for testing:

# a POST request
curl -X POST 127.0.0.1:8000/api/timeseries -F 'id_=cdd_sClimMean_BCCAQv2_PCIC12_historical-rcp85_rXi1p1_19610101-19901231_Canada' -F 'area=""' -F 'variable=cdd'

# identical GET request
curl "http://127.0.0.1:8000/api/timeseries?id_=cdd_sClimMean_BCCAQv2_PCIC12_historical-rcp85_rXi1p1_19610101-19901231_Canada&area=&variable=cdd"