Are there any good write-ups on creating RESTful APIs with Drupal? I see the services API, which I guess is how it's done. What I'm looking for, I suppose is a comparison of drupal vs. other frameworks for that particular purpose.
Update - a bit more info:
In particular, I'm probably going to want to be returning json, and ideally using http request verbs (PUT, POST, GET, DELETE) properly with the common resource urls. I.e. http://mysite/api/widgets/1 (POST -> create, GET -> view, PUT -> update, DELETE -> delete) as opposed to http://mysite/api/widgets/1/delete
The RESTful Web Services API is new in Drupal 8. For each REST resource, you can specify the supported verbs, and for each verb, you can specify the serialization formats & authentication mechanisms.
While Drupal still serves as a backend repository, front-end frameworks can talk to the database via API calls.
A RESTful API is an API that conforms to the architectural style of REST (representational state transfer). It accesses and uses data via HTTP requests to GET, PUT, POST and DELETE data types. In this post, you will be learning more about exposing your API in Drupal 9.
$client = \Drupal::httpClient(); $request = $client->post('http://demo.ckan.org/api/3/action/group_list', [ 'json' => [ 'id'=> 'data-explorer' ] ]); $response = json_decode($request->getBody()); Log in or register to post comments.
I cannot compare with other frameworks, but Service 3.x (that's version 3 of the Services module) provides a resource driven model for service with a REST backend (and an XML-RPC one). According to its documentation, you can create a new resource type quite easily (if you are familiar with Drupal) using a simple API as it takes care of JSON[P]/XML parsing and serialization.
Updated, prompted by David Eads' answer: I wouldn't start with Drupal and Services 3.x if the only end need is to build a RESTful service. They are not generic solution to build a data backend with a RESTful API. They should be used when what is needed is a CMS powered website exposing (parts of) its data through a RESTful API.
Drupal Services 3.0 makes creating REST services much easier than it was with the previous versions (2.x). Also Services 3.0 works with Drupal 6 and Drupal 7.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With