Closed vini-brito closed 3 years ago
Seems doable.
Let's first define the current behavior so the enhancement can be similar to the syntax.
http://jasonelle.com/docs/legacy/mixin/
With this new behavior then the mixin
should allow both text and object input.
"data": {
"simpsons": {
"@": "https://jsonbase.com/cl.ninjas/simpsons"
}
}
By default, the current implementation transforms that input to
"data ": {
"simpsons": {
"{{#include $root[\"https://jsonbase.com/cl.ninjas/simpsons\"]}}": {}
}
}
The url is requested and appended to the requires object inside VC.requires
The url is fetched inside the following function
- (void) include:(id)json
andCompletionHandler:(void (^)(id obj))callback;
Specifically in this line https://github.com/jasonelle/jasonette-ios/blob/develop/xcode/Jasonette/Core/Jason/Jason.m#L1308
When the object is obtained then is used here
NSMutableDictionary * refs = [VC.requires mutableCopy];
"https://jsonbase.com/cl.ninjas/simpsons" : [
"Homer",
"Marge",
"Lisa",
"Bart",
"Maggie"
]
Which is then resolved by st.js
https://github.com/SelectTransform/st.js/blob/develop/st.js#L242
And appended to the current JSON structure document in Jason.m
refs[@"$document"] = VC.original;
id include_resolved = [JasonParser parse:refs with:tpl];
VC.original = include_resolved;
return include_resolved;
Then proceeds to resolve the local references that starts with $
.
Basically for this to work is needed to pass a special param that indicates the request params.
maybe using the following syntax similar to http://jasonelle.com/docs/legacy/actions/#networkrequest
"data": {
"simpsons": {
"@": {
"url": "https://jsonbase.com/cl.ninjas/simpsons",
"method": "post|get",
"header": {
}
}
}
}
Naturally the previous syntax would still be valid.
@vini-brito what do you think?
I think this seems great!
Upon making some quick tests to implement this syntax. It can be a little cumbersome to implement. Because mixins are resolved before the parsing of the JSON structure.
This means that some regex is done to replace the syntax. Making an object instead of a string requires complex regex rules and probably some sort of JSON parser or curly braces matcher and balancer.
This can be implemented, but it would require some time.
A simpler solution can be made available using another syntax.
something like
{
"@" : "https://myurl[POST]"
}
following POST specs
https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
And maybe curl similar syntax
I added simple requests using post in iOS.
https://github.com/jasonelle/jasonette-ios/tree/mixin-post
some little testing should be done before merge :)
Now both android and ios have this :) Thanks for the idea 👍
Is your feature request related to a problem? Please describe. I'd like to hit API endpoints to get the mixins, but such endpoints do not allow for GET requests, only POST.
Describe the solution you'd like An option in the mixin node that would make the request a POST.
Describe alternatives you've considered I currently use integromat to make that conversion, for development it works fine, but when I reach production it will not be usable.
Identify which component would benefit from this feature
Additional context None for now.