jeffsebring / angular-wp-api

An AngularJS Client for WP-API
124 stars 15 forks source link

Try an array instead of a `{ paramX: '' }` object for designing queries #2

Closed kadamwhite closed 2 years ago

kadamwhite commented 10 years ago

Looking at the way queries are constructed with this library, I feel that the param1, param2 etc convention feels a bit arbitrary. Query levels (or directories, or what have you) will always start at the root (param1) and go until you don't specify another key; I'm not aware of a situation where you'd have a query for param1 and param3 without the intermediate param2.

Given this linearity, have you considered using an array for structuring these queries? As an example,

wpAPIResource.get( {
    param1: 'users',
    param2: wpAPIData.user_id
} );

would become

wpAPIResource.get([ 'users', wpAPIData.user_id ]);
// or
wpAPIResource.get([
  'users',
  wpAPIData.user_id
]);

This may avoid some confusion around the param1, param2 naming convention by flat-out removing it: You're now specifying a sequential number of URL parts that are assembled to create a final query.

Alternatively, you could introduce a more verbose query syntax in the manner of an ORM library like knex. That may be overkill for the time being!

jeffsebring commented 10 years ago

I agree. Do you have a suggestion for the best way to implement this?