REST doesn't seem to output the alias or path using GET. It seems there is also no way to provide the alias when using POST to create a node. Also The views module doesn't output the PATH of the nodes in a rest export.

Comments

daveferrara1 created an issue. See original summary.

dawehner’s picture

Component: base system » serialization.module
Priority: Critical » Major

Thank you for filing the bug report.

Even this seems to be critical for you, IMHO this is not critical for the Drupal project itself. Just ask yourself whether you would
release Drupal without this bugfix or not. Moving to major as of that.

Regarding the actual, did you tried to specify the path: alias field? Maybe report how you tried to create the content using REST.
Regarding the retrieval, #2539634: PathItem::delete() never runs because the path field type is a computed field in disguise and #2392845: Add a trait to standardize handling of computed item lists are really related bugs. These kind of fields are totally arguable a mess.

daveferrara1’s picture

Actually I think many projects are going to be affected by this. (if they are going to use REST)

PATHs are critical. REST is whats going to make Drupal 8 amazing. IMHO yeah Drupal 8 is not ready if REST is not usable 100%. REST is basically still in dev. I also noticed Patterns by content type also missing. Maybe that was pathauto that delivers that- IMHO that is also about as important out of the box like permalinks is for wp.

Basically getting a rest export from views, with a list of nodes that do not contain the path back to the node is quite a negative. Nearly useless.

Also, on a POST not getting to set the alias is also silly. Though, probably not that bad since most POSTS will be user data and FOrm submissions.

Also, the SEO negative it would cause if you were displaying a bunch of links to the node id and then also linking to it with the alias.

This POST FAILS:

{
"type": [
{
"target_id": "page"
}
],
"title": [
{
"value": "Hello world example"
}
],
"_links": {
"type": {
"href": "http://d8.ex.com/rest/type/node/page"
}
},
"alias":[
{
"value": "/example"
}
]
}

THIS POST SUCCEEDS BUT - no alias set and a new one - (Does not allow editing of the node after creation by admin) .

{
"type": [
{
"target_id": "page"
}
],
"title": [
{
"value": "Hello world example2"
}
],
"_links": {
"type": {
"href": "http://d8.ex.com/rest/type/node/page"
}
},
"path":[
{
"value": "http://d8.ex.com/example2"
}
]
}

dawehner’s picture

Well, conceptually you can fix those bits really after the release, so I would suggest you to just relax a bit. You know, there are bugs everywhere, its just a matter of software.

One interesting point which we have to keep in mind is that what you think is critical for your particular project is not critical in that way for the Drupal project as itself.
Feel free to read more about it on https://www.drupal.org/core/issue-priority

The following steps worked for me:

  • Enable hal, rest and serializer
  • Allow the anonymous user to create page content and Create and edit URL aliases
  • Post the following code to http://d8.dev/entity/node:
    {
    "type": [
    {
    "target_id": "article"
    }
    ],
    "title": [
    {
    "value": "Hello world example"
    }
    ],
    "_links": {
    "type": {
    "href": "http://d8.dev/rest/type/node/page"
    }
    },
    "path":[
    {
    "alias": "/example"
    }
    ]
    }
    
  • A new entry was created on 'http:/d8.dev/example'

Also, the SEO negative

Personally I could not care less :) SEO is IMHO mostly triggered by good content, so investing time in that is from my point of view a much better investment of any time, but you know, this is just my radical view.

daveferrara1’s picture

Priority: Major » Minor

The POST alias can be set with the correct permissions for the user and the correct JSON addition of:

"path": [
    {
      "alias": "/context22"
    }
  ] 

Thanks to @dawehner coming up with the POST solution.

Changed to minor. As the only issue now is that the path alias is not being provided via GET in either JSON or Hal+JSON, Views rest export also not providing the path alias.

I believe it should be in here:

 "path": [],
    "body": [
      {
        "value": "<p>Here is the body of the page.</p>\r\n",
        "format": "basic_html",
        "summary": ""
      }
    ],
wim leers’s picture

Title: REST GET and POST and Views Rest Export all missing Alias or Path » REST: how to set an entity's path alias when POSTing, and how to get an entity's path alias when GETting
Status: Active » Fixed
Related issues: +#2649646: Normalize path fields as part of the entity: allow REST clients to know the path alias

So there are two questions here:

  1. How to POST an entity and set its path alias. @dawehner answered this.
  2. How to GET an entity's path. This is being worked on at #2649646: Normalize path fields as part of the entity: allow REST clients to know the path alias.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

davidwbarratt’s picture

Version: 8.0.0-rc3 » 8.0.x-dev
Priority: Minor » Major

I noticed that if you don't save it with a pid it creates a new url_alias record. :(

rvanegmond’s picture

To set a custom alias I had to add the pathauto:false.

 "path": [

        {

          "pathauto" : false,

          "alias": "/context22"

        }

      ]