DistributedProofreaders / dproofreaders

Distributed Proofreaders is a web application intended to ease the process of converting public domain books into e-texts.
https://www.pgdp.net
GNU General Public License v2.0
47 stars 28 forks source link

api/v1_projects.inc: Return an error if client requests invalid field #1165

Closed bpfoley closed 5 months ago

bpfoley commented 6 months ago

As suggested by srjfoo. I agree with her that it's better to fail loudly rather than silent ignore unrecognized fields. If nothing else, it helps when a dev makes typos in client code.

I needed to do some code reorg to avoid repeating a subset of SQL column names and API field names for a third time.

Sandbox at https://www.pgdp.org/~bfoley/c.branch/invalid-field but it doesn't touch any non-API code.

Example call:

curl -s -X GET "$ROOT/api/v1/projects&field[]=pages_total&field[]=no_such_field" \
    -H "Accept: application/json" \
    -H "X-API-KEY: $INSERT_YOUR_API_KEY_KEY"