Skip to content
This repository was archived by the owner on Sep 13, 2018. It is now read-only.

rwanyoike/drupal-services-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

71 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Drupal Services API Client (Java)

This library is an easy-to-use Java client library for accessing the Drupal Services REST Server API.

Introduction

This library makes use of Retrofit as a REST client. For more information visit the Retrofit website.


The RestAdapter class generates an implementation of a resource interface.

RestAdapter restAdapter = new RestAdapter.Builder()
        .setEndpoint("http://127.0.0.1/endpoint") // Service endpoint
        .build();

NodeResourceForm resource = restAdapter.create(NodeResourceForm.class);

Each call on a generated resource makes an HTTP request to the webserver.

Map<String, String> params = new LinkedHashMap<String, String>();

params.put("pagesize", "10"); // Number of items to be returned
params.put("page", "2"); // Page number of results to return
params.put("fields", "id,title"); // Fields you want returned
params.put("parameters[\"type\"]", "article"); // Values used to filter results
params.put("parameters[\"status\"]", "1"); // ...

List<NodeEntity> nodes = resource.index("node", params);

Sessions

The SessionInterceptor class inserts a session header, and CSRF token.

SessionInterceptor interceptor = new SessionInterceptor();

RestAdapter restAdapter = new RestAdapter.Builder()
        .setEndpoint("http://127.0.0.1/endpoint") // Service endpoint
        .setRequestInterceptor(interceptor)
        .build();

UserResourceForm resource = restAdapter.create(UserResourceForm.class);

UserEntity user = new UserEntity()
        .setName("random") // Username
        .setPass("hackme"); // Password

Map<String, String> params = new EntityConverter<UserEntity>().convert(user);

SessionEntity session = resource.login("user", params);

// Requests now carry a session/token
interceptor
        .setSessionId(session.getId())
        .setSessionName(session.getName())
        .setCsrfToken(session.getCsrf());

When done.

// Logout of Drupal (invalidate session)
resource.logout("user");

// Clear SessionInterceptor 
interceptor
        .setSessionId(null)
        .setSessionName(null)
        .setCsrfToken(null);

*ResourceForm, and *ResourceJson

TODO: Explain Retrofit, GSON, and Drupal Services REST Server API limits.

Files

TODO: Add example.

About

Drupal Services REST client for Java

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages