Ticket #2330 (closed enhancement: fixed)

Opened 2 years ago

Last modified 2 years ago

Make api read-actions GETable

Reported by: icmurray Owned by: icmurray
Priority: major Milestone: ckan-sprint-2012-05-15
Component: ckan Keywords: [0.5-1d]
Cc: Repository: ckan
Theme: none

Description

Whitelist any GETable api actions, and optionally construct the query from url params rather than body.

Change History

comment:1 Changed 2 years ago by icmurray

  • Milestone changed from ckan-sprint-2012-04-30 to current-ckan-sprint-2012-05-15

comment:2 Changed 2 years ago by icmurray

  • Priority changed from awaiting triage to major

comment:3 follow-up: ↓ 4 Changed 2 years ago by icmurray

Implemented, providing two methods of passing an action's parameters. Either, each parameter is specified as a url parameter, eg

curl http://127.0.0.1:5000/api/3/action/package_search?q=police

or, for cases where a more complex data_dict is required, the data_dict can be parsed as a json-encoded dict in a single url-parameter called data_dict, ie:

curl http://127.0.0.1:5000/api/3/action/package_search?data_dict={'q':'police'}

As part of this ticket:

  • I noticed that all module-public members of the action modules were being loaded as actions (including functions imported from other modules). So I've cleared up the action modules to prevent this.
  • I've cleaned up the action modules to use get_or_bust() when accessing a passed in data_dict outside before it's been validated by a schema. This provides better error messages for clients.
  • provided a decorator, @side_effect_free, for users implementing their own actions through the IActions interface to be able to expose their custom/overridden actions as a GET request through the action API.

comment:4 in reply to: ↑ 3 Changed 2 years ago by icmurray

Replying to icmurray:

or, for cases where a more complex data_dict is required, the data_dict can be parsed as a json-encoded dict in a single url-parameter called data_dict, ie:

curl http://127.0.0.1:5000/api/3/action/package_search?data_dict={'q':'police'}

Another option is to have the data_dict json-encoded in the GET request's body. This is possible, but

1) Although permissable, it's not, as I understand it, conventional to have a GET request's body form the options of the request.

2) Caching proxies won't inspect the body of the request, only the URL.

comment:5 Changed 2 years ago by icmurray

  • Status changed from new to closed
  • Resolution set to fixed
Note: See TracTickets for help on using tickets.