New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add MATLAB generator #154
Merged
Merged
Add MATLAB generator #154
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The tests fail because I am using Node |
This comment has been minimized.
This comment has been minimized.
DainisGorbunovs
force-pushed
the
master
branch
from
February 15, 2020 21:44
f14b466
to
eb86a62
Compare
Please squash and merge this pull request. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
MATLAB generator
It generates two variants of MATLAB code, where the variants use either:
webread
,webwrite
withweboptions
)matlab.net.http.RequestMessage
)Generated output
Web services (
webread
/webwrite
)Many requests are possible, but not all. Supports only requests with
get
,post
,put
,delete
,patch
methods. Requests with a rich payload such as multiform data or form data are not possible. Binary and image payload is possible, however, is not recommended.The generator creates the following variables:
params
- query string parameters for the URLcookies
- n x 2 cell matrix with cookiesbaseURI
- URI without the query stringuri
- constructed URI fromparams
andbaseURI
body
- payloadoptions
-weboptions
objectThen it calls either
webread
(if there is no body to send in the request) orwebwrite
, returns it as aresponse
.Alternatively, if the
uri
is constructed wrong, it showsfullURI
given by cURL, and sends a request with this URI.HTTP Interface (
RequestMessage
)This is a more advanced API and allows to have higher freedom with requests.
The generator creates the following variables:
params
- query string parameters for the URLcookies
- n x 2 cell matrix with cookiesheader
- column vector of headers, which is transposed into a row vectoruri
- constructed URI from the base URI andparams
query parametersbody
- payload, it can be a character vectorThen it calls either
RequestMessage
with the method, headers and body to the encoded URIuri.EncodedURI
, returns it as aresponse
.Thanks / what I found helpful
Thanks, @NickCarneiro for the advice during this little project. Specifically, the below was helpful:
nc -l 3000
, then in another tabcurl -X POST http://localhost:3000 --data "hello=world"
(thanks @NickCarneiro)Findings
While trying to capture some cURL commands, I found that Safari may give a cURL command with
-Xnull
option. This means that Safari was unable to determine the request type. In order for any generator to return at least something, I am removing-Xnull
option from parsed cURL command. See util.js#L36.Limitations:
Below are the limitations I have found. They can be improved later in another pull request, should that be technically possible to achieve in MATLAB.
__type
, then we cannot store it as a key. Thus the only workaround seems to be to store everything as a character vector instead of a MATLAB structure.@cf512, @NickCarneiro