Bug: About new restful API
Issue Summary
ok , I try our new API , And I found there is some wrong when i use ajax twice continually
Steps to Reproduce
- This is my code
ghost.init({
clientId: "ghost-frontend",
clientSecret: "8919dc8debd1"
});
jQuery(document).ready(function() {
$.get(
ghost.url.api('posts', {
limit: 3
})
).done(function(data) {
var $result = $('#blog-posts');
$.each(data.posts, function(i, post) {
$result.append(
'<li>' + post.title + '</li>'
);
});
});
$.get(
ghost.url.api('posts', {
limit: 3
})
).done(function(data) {
var $result = $('#blog-posts');
$.each(data.posts, function(i, post) {
$result.append(
'<li>' + post.title + '</li>'
);
});
});
});
- The first request is right , and the second one return with an error

I think this is a bug because two times use one ghost api closure , In the ghost-url code
, they use the same apiUrl variable ,and the second time I call ghost.url.api , they use the same variable.
Technical details
- Ghost Version: master - latest commit: INSERT COMMIT REF
- Client OS: mac
- Browser: chrome latest
Have the same issue - tried doing a re-init before using the helper again, but this does not help.
Workaround
I actually found a way I can use it: doing an init at the beginning and then at each subsequential call (this is an infinite scroll implementation) I do not pass in any url part. Feels rather hack, though.
var postsUrl = ghost.url.api('posts', {limit: postlimit});
... when calling the function:
postsUrl=ghost.url.api('', {limit: postlimit});
However, I agree this should work different - actually this makes any use of the helper impossible when trying to access different API-Endpoints in the same script.
@chripf Thank you for your reply . I totally agree with your method . And I think i can change the ghost-url.js for my project . Because in one context , if you want to get user after get posts , it would be wrong , the url will be like this //www.frankxin.com/ghost/api/v0.1/posts/users . So I want to check if this kind of API is by designed or it's a mistake.
Confirmed, I'm working on a fix.
This will be closed automatically when the fix is merged.