Unable to follow links from POST-only resources
See original GitHub issueI’ve got a situation where I’ve got a resource that doesn’t really exist, but that I still want to follow links from.
I’m building a login/register flow, where the client will:
- Perform a
POST
to/authentication
with the username. - Receive a response containing one of two links - identified as either
rels/authentication/authenticate
orrels/authentication/register
- depending on whether the username exists. - Perform a
POST
to the link that was returned with the appropriate details.
So what I’ve done is:
- Create a new Ketting Client.)
- Perform a
GET
to/
to get the home document - Follow the link with the rel
rels/authentication
and perform aPOST
to this with the username - this is/authentication
- Follow the link with the rel
rels/authentication/authenticate
and perform a `POST to this with the username and password.
The result is that Ketting is then trying to do a GET
to /authentication
, which returns an error because the server can’t handle that, and then it errors out.
The code is effectively like this: (Restructured a little bit for brevity)
const startAuthResource = await apiRoot.follow("rels/authentication");
const response = await startAuthResource.post({ data: { username } });
const authResource = await startAuthResource.follow("rels/authentication/authenticate"); // <-- Problem occurs here
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Serving static web resources in Spring Boot & Spring Security ...
Problem. After I enabled Spring Security, hitting the static resource URL requires authentication. My relevent Spring Security Java config looks ...
Read more >I Can't Get My Hyperlink to Work - Small Business - Chron.com
If the hyperlink doesn't work correctly, troubleshoot the problem by checking the link ... default Web browser and open the linked page or...
Read more >How to share links on LinkedIn - John Espirian
Truthful answer: we can't be sure. But here's my best theory … LinkedIn pays attention to the state of the post only when...
Read more >How To: Get embed token using Get/Post only - Microsoft ...
Go to the Microsoft Power BI Embedded Sample site (link) and test your report. The input fields are as follows: Embed Token: {token...
Read more >Fix broken links to data - Microsoft Support
If you can't find or don't have access to the document that you originally linked to, you can prevent Excel from trying to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeahh… this is an issue.
The problem is that, generally, when following links, we follow links from a resource to another resource. When we get a POST response, the body of the response is not necessarily the representation of that
startAuthResource
resource.There’s two paths to make better, and I also have a workaround:
Approach 1: The response to the
POST
response should be considered to be the representation of that resource. The obvious header for this isContent-Location
:https://tools.ietf.org/html/rfc7231#section-3.1.4.2
If this makes the most sense for your case, we could add this feature to Ketting.
–
Approach 2: Follow links from State objects.
I had the idea to add a
.follow()
function toState
objects. This would allow you to follow links from any body, not just things that are ‘resources’:Workaround:
Sidenote is that it would also be nice if you could pass a
Link
type to.go()
so that last snippet would look like:Open a few more tickets for this. I think we’ll probably have a version 7 this month. Thanks for the report!