By Paul Mitchum, aka Mile23
Druplex is a half-baked way to attach a Silex RESTful API implementation onto Drupal 7.
It acts more as a proof-of-concept and some sloppy code to guide others along the way.
How To Install?
- Install Composer: https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx
- Go to the root directory of your Drupal 7 installation.
- Type this:
composer require mile23/druplex @dev
- Replace the root-level
index.phpfile with the one located in
vendor/mile23/druplex/index/druplex.index.php. Rename it to
index.php, of course.
- Put some settings in your site's
settings.phpfile. They should be in the
$druplexglobal variable. If you don't set these, druplex will use defaults, some of which might not be secure. Settings existing now:
- Point your web browser to
http://example.com/api. After logging in with the http authentication, you will see a Silex error. Success!
http://example.com/api/user/1and you'll see a bit of JSON representing user 1. Rock on.
api_password settings are used in protecting the Silex paths behind http authentication. You can't turn this off in settings. Default values: paul password
Note that in order to add Druplex to your Pantheon-hosted site, you'll have to say
composer require mile23/druplex @dev --prefer-dist since Pantheon (rightly) balks when you try to include git submodules.
This API is normalized on JSON.
Currently, you can:
- Query for a user by user ID through GET
- Create a user through POST
- Update a user through PUT
- Query for a user by an attached field
- Generate a one-time login for a user
Gets a sanitized version of the user for the user ID. Included here mostly for completeness and testing.
Returns a resource with
Post a user resource to the Drupal site.
If you try to send
pass it will fail. A random password will be generated for the user. Never send passwords over the internet, OK? :-) See the user one-time login part of this API for a solution to changing the password.
POSTing a user can only add fields which are present in Drupal's user schema. That is, no attached fields.
Change a user record.
You can change any field which is present in the Drupal user schema, other than
You can change the value of any attached field, too. You must include
fieldvalue. You can only change one field per PUT, and multivalue fields are unsupported.
Query for a user with a given attached field value.
You must specify the field name, the field column, and the value. The field column is the field's schema column. Fields can have more than one column, so we specify which column. For
text fields, the column is
Returns a sanitized user record, as with GET.
Get a one-time login URL for the given user.
Note that 'uli' is the Drush command for returning a one-time login, and that's why the name is used here.
Returns a resource with two properties:
useris the sanitized user object.
uliis the one-time login URL.
Where are the tests, Mr. Testing Man?
See TESTING.md for all the testing lowdown.