Skip to content

Instantly share code, notes, and snippets.

@dipamsen
Created October 26, 2022 09:47
Show Gist options
  • Save dipamsen/057d437dfd3c58c9a8eecc1d9162d28a to your computer and use it in GitHub Desktop.
Save dipamsen/057d437dfd3c58c9a8eecc1d9162d28a to your computer and use it in GitHub Desktop.
Reference for the p5.js Web Editor API

p5.js Web Editor API

Some Important Points:

  • Only the success responses are mentioned below. For each of the following, in case of an error, an error message will be present in the response, in the format
    {
      "message": "error message"
    }
  • For Authenticating the requests, a cookie is required which can be obtained from the Login endpoint.

Login - POST /editor/login

  • Auth: None
  • Body:
    {
      "email": "p5 email or username",
      "password": "p5 password"
    }
  • Response:

In this request, save the value of the set-cookie response header for further requests. In all authenticated requests, the Cookie header must be filled with this value.

Get Session - GET /editor/session

  • Auth - REQUIRED
  • Response:

Get All Sketches - GET /editor/{username}/projects

Get Sketch - GET /editor/{username}/projects/{sketchId}

Update Sketch - PUT /editor/projects/{sketchId}

  • Auth - REQUIRED
  • Body:
    {
      "files": [SketchFile],
      "id": "sketchId",
      "isSaving": false,
      "owner": SketchOwner,
      "updatedAt": DateTime
    }
  • Response:

Interfaces

UserInfo

{
  "email": "email",
  "username": "username",
  "preferences": {
    "fontSize": number,
    "lineNumbers": bool,
    "indentationAmount": number,
    "isTabIndent": bool,
    "autosave": bool,
    "linewrap": bool,
    "lintWarning": bool,
    "textOutput": bool,
    "gridOutput": bool,
    "theme": string,
    "autorefresh": bool,
    "language": string,
    "autocloseBracketsQuotes": bool,
    "soundOutput": bool
  },
  "apiKeys": [],
  "verified": "verified",
  "id": string,
  "totalSize": number,
  "cookieConsent": string
}

SketchInfo

{
  "name": "Sketch Name",
  "serveSecure": bool,
  "_id": string,
  "user": SketchOwner,
  "updatedAt": DateTime,
  "files": [SketchFile],
  "createdAt": DateTime,
  "slug": string,
  "__v": 0,
  "id": string
}

SketchOwner

{
  "_id": string,
  "username": string,
  "id": string
}

SketchFile

{
  "name": "filename/foldername",
  "content": "file contents",
  "children": [], // array of file ids present in this folder
  "fileType": "file" | "folder",
  "_id": string,
  "createdAt": DateTime,
  "updatedAt": DateTime,
  "id": string
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment