Skip to content

Definitive word on PACT and HATEOAS #102

@csydvs

Description

@csydvs

Just wanted to get the latest definitive word on recommendations for pact in a hypermedia-rich rest api world. For reference, we generally use spring-hateoas, but I think the same sort of question would apply using HAL, Siren, or anything else that implements the HATEOAS standard.

For anyone else asking the same thing, you might have stumbled across this "Traversion support in Pact" issue, but I think we've come a long ways from there. Now, we have this article (implemented in this repository) that talks extensively about validating endpoints that contain HATEOAS information on them, which is great support in this direction.

I think the question that I haven't found a super straightforward answer to is whether it's a bad idea to use provider state injection to set up contracts with APIs that the consumer is never actually aware of themselves. For example, in the example of an orders API, let's say that each order contains a list of items with each item having a link to the URL that provides more information about the state. Conceivably, these links might look something like https://example.com/orders/{orderId}/items/{itemId}, but with a hypermedia API, it's entirely conceivable that this API could be moved to https://example.com/items/{itemId} without any sort of change to the frontend, since the client is only aware of this link via hypermedia link. In this case, a contract with this items api might still make a lot of sense, but hardcoding that link in the contract doesn't make sense because the consumer is never aware of the specifics of the URL in the first place. This makes it seem like PACT and hypermedia links don't work well together, or at the very least, that the PACT might need to know more about the endpoint than the client itself does.

However, it seems like the pact V3 specification (and every library that implements it) has a way to inject provider state into a a contract. In this way, a consumer contract might specify basically that given that an item exists, and using the link to access it that the provider provides, the response should look a certain way. However, lots of the documentation seems to stop short of this most extreme case of providing the entire URL via provider state callbacks. Is there a reason for that? Is pursuing this going to end up being a bad idea?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions