Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drupal as backend for RESTful API?

Tags:

rest

drupal

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

like image 602
sprugman Avatar asked Jan 04 '11 22:01

sprugman


People also ask

Does Drupal support REST API?

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.

Is Drupal back end?

While Drupal still serves as a backend repository, front-end frameworks can talk to the database via API calls.

What is REST API Drupal?

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.

How do you call REST API in Drupal 8?

$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.


2 Answers

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.

like image 75
Pierre Buyle Avatar answered Oct 07 '22 01:10

Pierre Buyle


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.

like image 26
jbrass Avatar answered Oct 07 '22 01:10

jbrass