Jasonette / Jasonette/documentation

Discussion - Relative URL support

Open
#32 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
120
Forks
72
PR merge metrics
No merged PRs in 30d

Description

@brad came up with a great feature that takes care of relative URLs. Here's the PR: https://github.com/Jasonette/JASONETTE-Android/pull/35

The solution basically:

1. Looks at the `url` attribute of the `strings.xml` (The same url used for the root url of the app itself)
2. Use that as the root url with which all the relative URLs in the app will be resolved.

So for example, if the app's root URL is `https://www.jasonbase.com/things/nfk.json`, you would be able to specify just the relative path throughout the app like this:

```
{
"type": "image",
"url": "/avatar.png"
}
```

I like the idea of being able to make the URLs domain independent, which would make the JSON code much more reusable and powerful.

I have a couple of thoughts on this, and also wanted to put this out there for public discussion before we make any decision.

## Discussion 1. one root_url per view?

Maybe we can make this more flexible by stating the root url inside the JSON instead of using the hardcoded value from `strings.xml`? That way instead of having a single global root_url, we can namespace them per view. Also it's 100% powered by the JSON instead of hardcoded values. Here's an example:

```json
{
"$jason": {
"head": {
"root_url": "https://www.jasonbase.com/things",
"title": "relative path demo",
...
},
"body": {
"sections": [{
"items": [{
"type": "label",
"text": "go",
"href": {
"url": "/f3h.json"
}
}]
}]
}
}
}
```

## Discussion 2. Would this type of approach make the code less readable?

Upon thinking more about this I've come up with some concerns. One of the coolest things about Jasonette is you can basically walk through all the referenced JSON to figure out how the entire app works.

But maybe adding a relative url element puts more burden on people trying to figure out what the JSON does? After all, we're adding one more step for users to think about whenever they come across a url. I'm not suggesting this is a serious problem, but just wanted to bring this to the table and hear what others think.

## Discussion 3. Can we use templates to achieve similar effect?
Going back to above example, maybe we can achieve the same effect without introducing new concepts. For example we can `$set` a local variable called `root` and use that inside templates. Not exactly as succinct as the original solution suggested by brad but it does make the code more modular and shareable:

```json
{
"$jason": {
"head": {
"root_url": "https://www.jasonbase.com/things",
"title": "relative path demo",
"actions": {
"$load": {
"type": "$set",
"options": {
"root": "https://www.jasonbase.com/things"
},
"success": {
"type": "$render"
}
},
"templates": {
"body": {
"sections": [{
"items": [{
"type": "label",
"text": "go",
"href": {
"url": "{{$get.root}}/f3h.json"
}
}]
}]
}
},
...
}
}
}
```

What do you guys think? Any ideas/feedback welcome!

Contributor guide

No contributing guide indexed for this repository

Research direction

Review the proposed implementation in Jasonette/JASONETTE-Android pull request 35 alongside the relative URL examples in this discussion. The work is not ready to start until the project decides between a global root URL, a per-view JSON value, or templates; done would be a documented decision and agreed implementation scope.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, json
Domain
mobile
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.