Skip to content

Instantly share code, notes, and snippets.

@Fauntleroy
Last active December 27, 2015 14:39
Show Gist options
  • Save Fauntleroy/7342109 to your computer and use it in GitHub Desktop.
Save Fauntleroy/7342109 to your computer and use it in GitHub Desktop.
Centralized Resources plan
{{!
{
"resources": {
"photos": "photos",
"photos-profile": "photos-profile",
"other": "http://other-api.com/data.json"
}
}
}}
{
"resources": {
"photos": "http://www.photos-api.com/user/12345/photos/",
"photos-profile": "http://www.photos-api.com/user/12345/",
"thing": {
"url": "http://www.thing-api.com/user/12345/thing/",
"headers": {
"key": "12345"
}
}
},
"defaults": {
"http://www.photos-api.com/*": {
"headers": {
"key": "12345"
}
}
}
}
@pushred
Copy link

pushred commented Nov 6, 2013

And how do dynamic segments work?

@Fauntleroy
Copy link
Author

Dynamic segments should work here the same way you'd expect them to normally. If you define a dynamic segment in the URL it will attempt to use dynamic data to fill in the blanks when it's used on a page.

So if I define this in the resources.json:

{
    "resources": {
        "photo": "http://www.photos-api.com/user/12345/photos/{id}"
    }
}

And I use it in page.hbs:

{{!
{
    "resources": {
        "photo": "photo"
    }
}
}}

If I go to /page?id=5 I'll be fetching http://www.photos-api.com/user/12345/photos/5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment