Skip to content

AJAX Endpoint

Sebastian Rettig edited this page Nov 30, 2019 · 4 revisions

The Ajax-Endpoint is the endpoint that the Editor uses to load and save data from the server. Instead of providing different endpoints the H5P-Team used one endpoint which can be configured via the ajaxPath-field in the Editor-Integration-Object

As far as my research goes, it works like this:

GET or POST /ajaxPath?action=

1. Get Content-Type-Cache

Method: GET /ajaxPath?action=content-type-cache

Response:

{
"outdated": boolean,
"libraries": Array<Library>
}

See Communication with the H5P Hub for details on how to construct the content type cache (which confusingly is actually a "view" of the user on the usable libraries).

Example of a response

2. Get Libraries

Method: GET /ajaxPath?action=libraries?machineName=<machine_name>&majorVersion=<major_version>&minorVersion=<minor_version>

Response:

{
"semantics": LibrarySemantics,
"language": LibraryLanguage,
"javascript": Array<JSDependency>,
"css": Array<CSSDependency>,
"translation": LibraryTranslation
}

3. Post Libraries

Method: POST /ajaxPath?action=libraries

Body:

Array<LibraryName>

Example: ["H5P.AdvancedText 1.1", "H5P.AppearIn 1.0"]

Response:

Array<Library>

4. Post files

Method: POST /ajaxPath?action=files

Body: file

Response:

{
mime: MimeType,
path: Path
}

5. Filter

Method: POST /????

Body (form data):

libraryParameters = {
  library: string, // machine name with whitespace
  params: any, // content paramteres
  metadata: { // = subset of IContentMetadata
    title: string,
    license: string
  }
}

Response:

{
  data: {
    // ... the filtered data from the request (same basic structure)
  },
  success: boolean
}

I hope this makes it a little bit clearer and helps you understand how the H5P-Editor works. There might be other mechanisms that I am not aware of, so please feel free to contribute and share your knowledge about the H5P-Structure.