RESTful-Drupal / restful

RESTful best practices for Drupal
https://drupal.org/project/restful
419 stars 173 forks source link

Relationships URL is not working #1015

Open rafatwork opened 6 years ago

rafatwork commented 6 years ago

My restful powered API seems to be working fine, with resources etc working great. Only thing I'm stumbling upon is that the 'relationships' URL that is being constructed, doesn't work.

My output contains this URL: api/v1.0/articles/12345/relationships/tags

But when I visit that URL, it displays this:

{
type: "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
title: "The entity ID 12345/relationships/tags does not exist.",
status: 422,
detail: "Unprocessable Entity; Validation errors."
}

Anyone experienced this issue before?

bbonora commented 6 years ago

I think what you're trying to do is something like this api/v1.0/articles/12345/?includes=tags. This will include a new property called includes in the response. It's also important to note that the resource needs to be using the json_api format in order to work properly. You can set the format using the module settings in the dashboard or you can add something like this to this to your class:

/**
 * Class Blogs__1_0
 * @package Drupal\freq_api\Plugin\resource\entity\node\blogs
 *
 * @Resource(
 *   name = "blogs:1.0",
 *   resource = "blogs",
 *   label = "Blogs",
 *   description = "Export the Blogs with all authentication providers.",
 *   authenticationTypes = TRUE,
 *   authenticationOptional = TRUE,
 *   dataProvider = {
 *     "entityType": "node",
 *     "bundles": {
 *       "blog_post"
 *     },
 *   },
 *   majorVersion = 1,
 *   minorVersion = 0,
 *   formatter = "json_api"
 * )
 */

Notice how * formatter = "json_api" in the resource plugin definitions properties.