Mathoid: Add public and back-end endpoints#339
Conversation
|
Bike-shedding about |
There was a problem hiding this comment.
I must admit I like formula much better than q, but left it for compatibility.
|
@d00rman I'm not really sure how to use this.
What would be the actual link to the images: |
|
@physikerwelt I agree that what you have described would be the ideal usage. Originally I thought about supplying Field ExtractionThe current spec-driven way of hooking up services in RESTBase does not allow us to extract different response fields. When supplied with HeadersThe bigger problem I see are the headers - they variate depending on the actual rendering format (which, of course, makes perfect sense). However, that also means that we would need to keep track of them in two places - Mathoid and RESTBase. I am really not a fan of that idea. Potentially, though, this could be solved if Mathoid were to supply RESTBase with the headers as well for {
"mml": "...",
"mml-headers": {
"content-type": "xml+mathml",
// other possibly mml-specific headers
}
// etc ...
}Current Work-aroundIn order to achieve the behaviour you described, you would need to make three separate requests: one for |
2fadd57 to
2b46c62
Compare
This surprises me. The tests do access different body parts of the request while templating a new request, so I would think this should work for named responses as well.
Previously, we addressed a very similar issue by creating a mime-like format for Parsoid pagebundles: {
svg: {
headers: { .... },
body: '<svg>...</svg>'
},
png: {
headers: {...},
body: '<base64-encoded-binary (yeah..)>'
},
mml: {
headers: {..},
body: '...'
}We could recycle this.
The idea would be that the hash is sufficent to construct a URL for each of the variants. Example:
Constructing this URL shouldn't be harder than concatenating two strings, so the POST end point wouldn't necessarily need to return more than the hash. Returning the MathML content on POST could be doable as a special case. Alternatively, the extension could GET MathML, and POST the spec / re-request the MML only if that 404s. |
|
"Alternatively, the extension could GET MathML, and POST the spec / re-request the MML only if that 404s." |
I'l get moving on that probably tomorrow. I'll need to do some changes to Mathoid first, though (most notably, allow it to send back the headers as well for So the sequence of events should end up being:
@physikerwelt does the extension depend on the exact format returned by Mathoid for |
I've added a new output format ( |
2b46c62 to
90bacf7
Compare
So, I tried to do this: return:
status: 200
headers: '{$$.merge({$$.merge($.mathoid.headers, {"x-resource-location": $.request.headers.x-resource-location})},$.mathoid.body.{$.request.params.format}.headers)}'
body: '{$.mathoid.body.{$.request.params.format}.body}'... but I'm getting syntax errors from at offset 12, column 13, while for the body line the error is: So it seems like extracting fields based on a named param is not going to fly :( Perhaps #347 might help there @gwicke ? |
|
@d00rman, try this syntax (untested): return:
status: 200
headers: '{$$.merge($$.merge($.mathoid.headers,{"x-resource-location": $.request.headers.x-resource-location}),$.mathoid.body[$.request.params.format].headers)}'
body: '{$.mathoid.body[$.request.params.format].body}' |
90bacf7 to
6e052f3
Compare
|
Soo, now the checks are failing because all of the pageviews tests from #350 are failing. WTH? |
|
This PR is now ready for review @wikimedia/services && @physikerwelt . I have changed the PR description to reflect the new way of interacting with the API (TL;DR just as @physikerwelt wanted it to be) |
|
@d00rman at a first glance it looks reasonable to me. However, given the long and informative discussion in this github issue, I think it would be good to add some more documentation. |
There was a problem hiding this comment.
@Pchelolo the security stanza has been added to the POST public endpoint in spec/media/v1/mathoid.yaml
This commit adds two public routes:
- `POST /{domain}/media/math`
- `GET /{domain}/media/math/{hash}`
The first allows clients to perform a POST request to ask for a formula
to be rendered. It takes the same parameters as Mathoid, namely `q` (the
formula to be rendered), `type` (the format or type of the supplied
formula) and `format` (the desired output format). Only `q` is
mandatory, `type` defaults to `tex`, while `format` is presumed to be
`json` if not supplied. Internally, the request is saved using the
*post_data* module. The request hash is therefore calculated and is used
to determine if the given formula has already been rendered by Mathoid
in the sought output format. If so, the stored version is returned.
Otherwise, a request is issued to Mathoid and its result is stored and
returned. In either case, the response contains the `x-resource-location`
header which can be used to perform subsequent, low-latency requests to
obtain the same render via the second public endpoint.
Note that the endpoints and their storage are organised in such a way as
to be domain-independent. This commit introduces a new, global domain -
`window.wikimedia.org` - and all Mathoid requests are internally
remapped to it. In other words, if a render with the data hash `12345`
exists, it can be retrieved equally from all domains, regardless of the
initial request's domain.
Also, this commit reorganises slightly the configuration files.
only the sought format
Global domain's /sys/ spec mistakenly contained a second definition of the pageviews module, which was causing pageviews tests to fail. This commit removes it.
35e608b to
64b96c0
Compare
|
@physikerwelt I have added a better description of the endpoints in the public spec documentation so that users know how to use it. |
|
👍 |
There was a problem hiding this comment.
Why do we need to add this module to default-sys domain? It's used only by method, which's only in global-sys domain. May be better to inline it there?
There was a problem hiding this comment.
Heh, we actually can't. Both of them are used by the routes loaded during testing form specs/test.yaml so they have to stay in default-sys
There was a problem hiding this comment.
But we have config.test.yaml for that?
There was a problem hiding this comment.
And have these slight differences between the two? I'm voting for sanity here.
There was a problem hiding this comment.
Works for me, it was just a little thing.
There was a problem hiding this comment.
To clarify, neither of these modules create any resources on start-up, so the net result is the same
|
LGTM |
Mathoid: Add public and back-end endpoints
This patch set adds the 'complete' output format which is equal to the 'json' one except that it also includes the headers for individual types in the response body as well. The output specification is identical, except that the 'mml', 'svg' and 'png' fields are now objects containing the 'body' and 'headers' fields. Note: this format is needed by RESTBase for wikimedia/restbase#339 Bug: T102030 Change-Id: I37d45cda1ceb5255a580b3a2f291268c1f270c53
This PR adds two public routes:
POST /{domain}/media/math/{format}GET /{domain}/media/math/{format}/{hash}The first allows clients to perform a POST request to ask for a formula to be rendered. It takes the same parameters as Mathoid, namely
q(the formula to be rendered) andtype(the format or type of the supplied formula), withformat(the desired output format) being present in the URI. Onlyqis mandatory whiletypedefaults totexif not supplied. Internally, the request is saved using the post_data module. The request hash is therefore calculated and is used to determine if the given formula has already been rendered by Mathoid. If so, the stored version is returned. Otherwise, a request is issued to Mathoid (to its/completeendpoint) and its result is stored. The API returns only the portion (body, headers) relevant to the sought format. In either case, the response contains thex-resource-locationheader which can be used to perform subsequent, low latency requests to obtain the same render (but possibly in a different format) via the second public endpoint.Note that the endpoints and their storage are organised in such a way as to be domain-independent. This PR introduces a new, global domain -
wikimedia.org- and all Mathoid requests are internally remapped to it. In other words, if a render with the data hash12345exists, it can be retrieved equally from all domains, regardless of the initial request's domain.Also, this PR reorganises slightly the configuration files.
Bug: T102030