# Destroying a users session via api

**URL:** <https://meta.discourse.org/t/destroying-a-users-session-via-api/49794>\
**Category:** Development\
**Tags:** rest-api\
**Created:** [6 Setembro , 2016 22:15 UTC](https://meta.discourse.org/t/destroying-a-users-session-via-api/49794 "2016-09-06T22:15:01Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![mpalmer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mpalmer/32/45740_2.png) [@mpalmer](https://meta.discourse.org/u/mpalmer)\
**Post date:** [6 Setembro , 2016 23:17 UTC](https://meta.discourse.org/t/destroying-a-users-session-via-api/49794/4 "2016-09-06T23:17:21Z")

</div>

Looking at the code, the redirect is actually expected behaviour… sort of:

```
def destroy
  reset_session
  log_off_user
  if request.xhr?
    render nothing: true
  else
    redirect_to (params[:return_url] || path("/"))
  end
end

```

If you add an `X-Requested-With: XMLHTTPRequest` header to your request, that’ll suppress the redirect, and you’ll get an empty-body `200 OK` instead.

---

_[View the full topic](https://meta.discourse.org/t/destroying-a-users-session-via-api/49794)._
