I'm building an API that will use JSON. The primary use for this API will be AJAX in a browser but it may also be used server-side by user's PHP scripts, etc.
There are 2 ways I can do this (I think):
- Build the API so that it uses HTTP headers to set a session cookie and retrieve all data for maintaining state by using the
COOKIE['session_id']
(pseudo code) - Build the API so that it returns
session_id
and allows the user's JavaScript code to set its own cookie forsession_id
I'm a little lost in general. Which way will be more secure (CSRF, etc), easily understood by developers, easier to make server-side changes without telling users they have to update their code.
Also, do you recommend using JSON-RPC spec, and if so, do one of these methods better support JSON-RPC?
Any help is much appreciated.