Skip to main content
100%

Gist b99e7499ed393379a3884f1e1c51fa33

✓ Published0🌍 Public
LLucienPerouze
Last edited Feb 15, 2018
Created on Feb 15, 2018

This example demonstrates a RESTful API sandbox for a messaging system, showing how to handle POST and GET requests to add and retrieve chat messages. The code uses Sandbox.define() to create endpoints for `/addMessage` and `/getMessages/{userId}/{index}`, validating JSON content types and required fields. Messages are stored in an in-memory state object, which persists across requests within the sandbox. The GET endpoint filters messages by an index parameter, marks messages from the requesting user with a `me` flag, and returns a JSON response with the last message index and the filtered message list, using the Underscore.js library (`_`) for array filtering and mapping operations.

AI-generated description

Similar vizzes