thoughtworks / pacto

Pacto settles disputes between JSON providers and consumers
thoughtworks.github.io/pacto
MIT License
401 stars 58 forks source link

Proposal: Provider Actors #115

Closed maxlinc closed 10 years ago

maxlinc commented 10 years ago

Consumer Actor Adapter

The roadmap for Pacto v0.4.0 will shift towards a more hexagonal or "Ports and Adapters" architecture. One of my planned adapters is Actors - in the sense of "courtroom re-enactments".

The Provider Actor adaptor type will drive the provider responses.

Responsibility

The Provider Actor is responsible for creating responses to Requests which have been generated by the Consumer Actor.

This is less open-ended than the consumer actor. It will always receive a Faraday::Request and is expected to create a Faraday::Response. See the notes on Consumer Actor about why I think we should use Faraday::* for objects that represent actual HTTP transactions rather than abstract templates and rules for the service.

Concrete Implementations

Currently we have two concrete implementations that should be refactored to match the pattern:

# Generates a response for the service
# @param contract [Pacto::Contract] the contract describing the service.
# @params request [Faraday::Request] a request ot respond to
# @return [Faraday::Response]
def react(contract, request)
  # respond
end

Proposed Port Locations

This should take the place of Contract#stub_contract! and Contract#provider_response.

There should be a default Provider Actor set at the top-level (Pacto or Pacto::Configuration) or "prosecutor" level, just like with Consumer Actors.

maxlinc commented 10 years ago

Example actor added via #118.

Close - split LiveProviderActor to #143.