0

I am looking for complete and updated documentation for Restful web services.

For example, for the user login, we have to post the following data.

POST: http://example.com/user/login?_format=json
Content-type: application/json
Data: { "name": "admin", "pass": "myPassword" }
Response: 200 OK

This will properly log in via cookie authentication, and return a result similar to this.

    {
      "current_user": {
        "uid":"1",
        "roles":["authenticated"],
        "name":"admin"
      },
      "csrf_token":"abc123",
      "logout_token":"def456"
    }

How do I log out the user I just logged in with?

I found RESTful Web Services module overview, but I still don't understand how to log out.

Using the following request gets back a 403 Forbidden error.

POST: http://example.com/user/logout?_format=json
Content-type: application/json
Data: { "name": "admin" }

What am I missing?

  • They are the same URLs you normally use on Drupal, so the one to log out is user/logout, and the one to see the profile of the user #1 is user/1. – kiamlaluno Apr 24 '17 at 7:25
  • Thanks @kiamlaluno, Can you please tell me how can I logout using RestWS. I have tried several ways but no one is working. – visabhishek Apr 24 '17 at 8:41
  • Core REST modules are not the same as the RestWS contrib module. – Kevin Apr 24 '17 at 12:49
  • hi @visabhishek, which drupal 8 version you are using. – vijay Apr 25 '17 at 5:29
0

As per documentation you can do like this.

Logout

GET http://example.com/user/logout
Content-type: text/html
200 - OK

Note: Do not pass "?_format=json" it is not accepting.

  • I am using Drupal 8.3.1. Thanks vijay above code is working fine, How can I get success message or any return value after logout. – visabhishek Apr 25 '17 at 6:21
  • No visabhishek, currently drupal not providing any logout message for REST, Even it's return type is "text/html". Base on return status code you need to show message from client side. – vijay Apr 25 '17 at 6:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.