Tag Archives: Web Service

Django REST framework – Setting permissions

Let’s continue our example in

 

So now we have a working endpoint @ http://127.0.0.1:8000/custom/get/.
django-rest-framework-permissions-1
Continue reading Django REST framework – Setting permissions

Advertisements

Django REST framework – Create endpoints for custom actions

We have talked about how to use Django REST framework to create a RESTful backend for model CRUD.

 

But sometimes we would like to have some backend endpoints for non-model actions. Here is a very good article written by Jeremy Satterfield about non-model endpoints on Django REST framework.

 

The Django REST framework offer us a few ways to implement the web service. Some of them are very convenience to use but in return giving you less flexibility. The following example will make use of the APIView class to create a custom GET request end point.
Continue reading Django REST framework – Create endpoints for custom actions

Django – Setup Django REST framework

We have the Django welcome page working already.

 

I would like to create some REST services on that setup. We could make use of the Django REST framework.

Let’s keep working on our <project_root>/django_poc project to manage articles by REST. The example in this post are based on the Django REST framework quickstart tutorial. It’s good to go through all of them which could give you a more thorough idea on how the REST framework works.

1. Install the Django REST framework in your virtualenv.

pip install djangorestframework

Continue reading Django – Setup Django REST framework

Drupal 8 – Create a node through RESTful Web Service @ 1

In the previous posts, we have gone through some examples about working with Drupal 8 RESTful web service.

 

We can also add node to Drupal through web service. But as i mentioned before, the RESTful feature is not fully completed so we can only create a node with a title. Here is a example web service client in PHP using Guzzle.
Continue reading Drupal 8 – Create a node through RESTful Web Service @ 1

Drupal 8 – Login in Guzzle Web Service Client @ 1

1. Get your PHP client ready by following my previous post.

 

2. Update your index.php as follow.

<?php
  require 'vendor/autoload.php';
  use Guzzle\Http\Client;
  use Guzzle\Plugin\Cookie\CookiePlugin;
  use Guzzle\Plugin\Cookie\CookieJar\ArrayCookieJar;

  $cookiePlugin = new CookiePlugin(new ArrayCookieJar());
  $client = new Client('http://drupal8.localhost.com');
  
  $client->addSubscriber($cookiePlugin); 
  $request = $client->post('user', null, array(
    'name' => '<username>',
    'pass' => '<password>',
    'form_id' => 'user_login_form',
  ));
  $request->addHeader('Accept', 'application/json');

  $response = $request->send()->json();

  print '<pre>';
  print_r($response);
  print '</pre>';
?>

Continue reading Drupal 8 – Login in Guzzle Web Service Client @ 1

Connect Drupal 8 RESTful Service with Guzzle PHP Web Service Client @ 1

Previously I have setup a a Drupal 8 which is RESTful ready.

Guzzle is a PHP HTTP client & framework for building RESTful web service clients. In this example, we would create a simple .php to fetch a node from Drupal 8.

1. Make sure you have the Composer installed. You can refer to my previous post.

Continue reading Connect Drupal 8 RESTful Service with Guzzle PHP Web Service Client @ 1

Drupal 8 – Setup the RESTful Service @ 1

After studying Drupal 8 for a few days, i got the feeling that there are still a lot of works to polish it before a beta or RC release. And lacking documentation is another big problem to kick start with Drupal 8. This post may help you to get some simple idea on how to setup RESTful service in Drupal 8 but very likely, the details will change in the future.

1. Enable the RESTful Web Services.
drupal-8-setup-rest-service-1
Continue reading Drupal 8 – Setup the RESTful Service @ 1

Drupal – Send SOAP Request by NuSOAP

In PHP, we can use cURL library for generating SOAP request.
PHP – Send a SOAP Request by cURL

Except using the cURL library, we can also use the NuSOAP. The NuSOAP provides much more convenient way to create the SOAP request and it can be used in Drupal. The following example is base on the Blog post written be Eric London.
Executing a SOAP call from Drupal using nusoap Continue reading Drupal – Send SOAP Request by NuSOAP