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

The module does not honor the given api endpoint #5

Closed
XVincentX opened this Issue Apr 19, 2015 · 9 comments

Comments

Projects
None yet
2 participants
@XVincentX
Contributor

XVincentX commented Apr 19, 2015

Hey,
I am using this simple code to try an hypermedia API

export default class pollsService {
  constructor(hrRoot) {
    this.mainLink = hrRoot('http://suerapi.org').follow({ headers: { Accept: 'application/hal+json' } })

    this.mainLink.$promise.then((hrRootLink)=> {
        console.info("Fetched")
        this.hrRootLink = hrRootLink
        hrRootLink.$$links.questions[0].follow().$promise.then((q) =>{console.info(q)})
    }, (error) => {console.log(`Error during hypermedia fetching: ${error}`)})

  }
}

Even if the first request is correctly issued to http://suerapi.org, the following one are not appending the host given in the first call.

image

I was expecting to see http://suerapi.org/questions

Am I missing something here?

@petejohanson

This comment has been minimized.

Owner

petejohanson commented Apr 20, 2015

@XVincentX Can you add the HAL response for the root here? My hunch is the responses is a relative one, instead of an absolute URL.

I have a long standing TODO item about handling relative URL resolution prope rly, I have a feeling that is the issue you are encountering.

@XVincentX

This comment has been minimized.

Contributor

XVincentX commented Apr 20, 2015

Yes, I confim that the returned urls are relative!

@petejohanson

This comment has been minimized.

Owner

petejohanson commented Apr 20, 2015

@XVincentX Please give angular-hy-res v0.0.14 a try, and let me know if things are improved. I've added relative URL handling to hy-res, and bumped both core hy-res and angular-hy-res accordingly.

Thanks.

@XVincentX

This comment has been minimized.

Contributor

XVincentX commented Apr 20, 2015

Hey,
it works, it is correctly constructing relative url, but the Accept header, specified in the first follow call, is not added into the request. Should I specify it every time?

@petejohanson

This comment has been minimized.

Owner

petejohanson commented Apr 20, 2015

Until I have a chance to add the automatic Accept header generation based on registered extensions, you can either:

  1. Specify it in each call to followOne/followAll.
  2. Add it to the default headers in the AngularJS $http service itself.
@XVincentX

This comment has been minimized.

Contributor

XVincentX commented Apr 20, 2015

Adding it to http service will fit my current use case, but woud be "dangerous" for larger applications.

Thank you again for your help. Looking forward to see your update 👍
Keep up the great work!

@petejohanson

This comment has been minimized.

Owner

petejohanson commented Apr 20, 2015

@XVincentX Yes, that certainly is dangerous, polluting the global scope like that.

Please give angular-hy-res v0.0.15 a try, I've added the automatic Accept header generation based on registered extensions.

@XVincentX

This comment has been minimized.

Contributor

XVincentX commented Apr 20, 2015

Working as expected! Great!

@petejohanson

This comment has been minimized.

Owner

petejohanson commented Apr 20, 2015

Ok, great. I'm going to close this, feel free to re-open if needed.

Thanks.

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