function JSONCallback(event) % JSONCallback - Callback called by modelit.webserver.Server object for generating a % JSON response. % % CALL: % JSONCallback(event) % % INPUT: % event: <modelit.webserver.HttpExchange> % with the request data and methods to generate a response. % % OUTPUT: % No output, a response with a JSON object is return to the client. % % EXAMPLE: % server = modelit.web.server.Server(8081, @JSONCallback).start() % % % Open a webbrowser and type: http://localhost:8081 in the address bar % % Now a json message appears in the browser. % % Copyright 2020 Modelit, www.modelit.nl % Generate the response response = JSON(event); % Set the MIME type and allow Cross Origin Resource Sharing event.addResponseHeader('Content-Type', 'application/json',... 'Access-Control-Allow-Origin', '*'); % Send the response back to the client event.send(200, response); %__________________________________________________________________________ function text = JSON(event) % JSON - Make a simple JSON object with Matlab method. % % CALL: % text = JSON(event) % Make a simple JSON object with Matlab method S = struct('date', datestr(now),... 'method',event.getRequestMethod,... 'from',event.getRemoteAddress); text = jsonencode(S);