# set a Cookie for a restful service?

**URL:** <https://forum.xojo.com/t/set-a-cookie-for-a-restful-service/41043>\
**Category:** Web\
**Created:** [December 7, 2017, 7:50pm UTC](https://forum.xojo.com/t/set-a-cookie-for-a-restful-service/41043 "2017-12-07T19:50:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brian\_O\_Brien](https://forum.xojo.com/user_avatar/forum.xojo.com/brian_o_brien/32/20096_2.png) [@Brian\_O\_Brien](https://forum.xojo.com/u/Brian_O_Brien)\
**Post date:** [December 7, 2017, 7:50pm UTC](https://forum.xojo.com/t/set-a-cookie-for-a-restful-service/41043/1 "2017-12-07T19:50:56Z")

</div>

I’m trying to write a server and make use of the session id. i[/i]  
When a request url comes to the server i may want the request to be handled by an existing session with that session identifier.  
I assume cookies are the way this is done.

```auto
http://myserver:myport/q1=v1
```

If the url doesn’t have an identifier parameter then a cookie must be given to the client that contains that identifier and the client.  
Then the client can use the value of that cookie as part of the url for subsequent requests to the server.

```auto
http://myserver:myport/identifier=ABC123?q2=v2
```

So given that the session open event is the one who knows it’s identifier how does the App know the identifier to put in the cookie?

The idea being that the servers sessions need to be stateful and this is what I’m trying to achieve and i’d like to be able to connect back to a server and get the web page back in the same state and avoid destroying the session between url calls to it.

---

<div class="post-metadata">

**Author:** ![Steve\_Upton](https://forum.xojo.com/letter_avatar_proxy/v4/letter/s/6de8d8/32.png) [@Steve\_Upton](https://forum.xojo.com/u/Steve_Upton)\
**Post date:** [December 7, 2017, 9:37pm UTC](https://forum.xojo.com/t/set-a-cookie-for-a-restful-service/41043/2 "2017-12-07T21:37:10Z")

</div>

You’re right about the technique but I wouldn’t call it a cookie, rather just a session ID.

A cookie is typically used at the end user level by a browser, stored locally, and supplied in the header of HTTP requests. A session ID is supplied as a field in the URL or a POST (form-style) field for API access of a restful service.

otherwise, yes.

---

<div class="post-metadata">

**Author:** ![Ian\_Jones](https://forum.xojo.com/user_avatar/forum.xojo.com/ian_jones/32/2076_2.png) [@Ian\_Jones](https://forum.xojo.com/u/Ian_Jones)\
**Post date:** [December 8, 2017, 9:52am UTC](https://forum.xojo.com/t/set-a-cookie-for-a-restful-service/41043/3 "2017-12-08T09:52:28Z")

</div>

@Brian O’Brien I’m confused by your question, you call it a restful service but then talk about using `Session` and getting back to the web page.

Is it a “normal” web app where a user visits the app and gets pages to interact with?

Or is it an API service (maybe using `HandleSpecialUrl`) where you want to return JSON, XML or whatever?

---

<div class="post-metadata">

**Author:** ![Brian\_O\_Brien](https://forum.xojo.com/user_avatar/forum.xojo.com/brian_o_brien/32/20096_2.png) [@Brian\_O\_Brien](https://forum.xojo.com/u/Brian_O_Brien)\
**Post date:** [December 8, 2017, 3:18pm UTC](https://forum.xojo.com/t/set-a-cookie-for-a-restful-service/41043/4 "2017-12-08T15:18:48Z")

</div>

Its a service … however returning simply json or xml is not what I have in mind, i wanted to present the user with a web page of the WebPage class in Xojo. I want the session to remain alive until there is a timeout if the user closes the page they can reopen if they have the session id. Which probably doesn’t need cookies?

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 7:01pm UTC](https://forum.xojo.com/t/set-a-cookie-for-a-restful-service/41043/5 "2020-10-29T19:01:16Z")

</div>


