Skip to content
This repository has been archived by the owner on Sep 1, 2021. It is now read-only.

Mapi apps rendering thrift communication

Demetrios Skamiotis edited this page Jul 8, 2020 · 10 revisions

Mapi <-> apps-rendering thrift communication

apps-rendering/api-models/thrift/src/main/thrift/appsRendering.thrift

mobile-apps-api/mobile-item/app/controllers/RenderedItem.scala

Within this relationship we have a 2 way communication channel.

Overview:

  • MAPI requests and fetches article/content data from CAPI.
  • However MAPI also includes other necessary information as well as the content and 'bakes' it into the data.
  • This comes in the form of a BLOB (more on that here)
  • MAPI sends new form as a BLOB to apps-rendering
  • apps-rendering is then able to access the the data given this and then produce the relevant HTML, CSS and JS as necessary.

Mapi fetches content from CAPI

import com.gu.contentapi.client.model.v1.ItemResponse

Mapi ---> apps-rendering:

  • Once MAPI has baked the article from CAPI as well as other data it serializes this data as a BLOB.
  • A Payload .thrift is sent to apps-rendering, as a BLOB, containing data values needed to construct a webview.
  • apps-rendering can then Deserialize the BLOB, in order to construct the HTML, CSS and JS using this data in rendered form for the Webview.
  • Now apps-rendering, provides the type definitions required to request an HTML page here

apps-rendering ---> Mapi:

  • apps-rendering rendered the deserialized data in the form needed with any logic
  • HTML, CSS and JS is sent in rendered form back to Mapi
  • Mapi can then pass this onto the client to the Webview

EXAMPLE apps-rendering/itemResponse.js

var ItemResponseSerde = /** @class */ (function () {
    function ItemResponseSerde() {
    }
    ItemResponseSerde.read = function (protocol) {
        var _a, _b, _c, _d, _e, _f, _g, _h;
        protocol.readStructBegin();

In CAPI > https://github.com/guardian/content-api-models/blob/master/models/src/main/thrift/content/v1.thrift We have:

struct ItemResponse {

    1: required string status

    2: required string userTier

    3: optional i32 total