What is the "state" in server route handler?

exports.handler = function(request,response,state) {

I can see in the PUT example, we can get JSON body from the state? Why not get it from the request body?

	var title = $tw.utils.decodeURIComponentSafe(state.params[0]),
	fields = $tw.utils.parseJSONSafe(state.data);

So what is this state actually? Is there a doc for it, or where is the essential code of it? I can write a TS type for it if I understand it.

Hi @linonetwo the “state” object should perhaps have been called “context” – it is a collection of properties that (mostly) relate to the state of the server, rather than the individual request.

I say “most”, because as you can see from the code, there is actually a bunch of properties that are derived from the current request (eg urlInfo), which should perhaps have been a separate object.

1 Like

Thank you Jeremy, I think context may be better, most server frameworks use it.

I can start using context in my new plugin…