https://github.com/gregoryv/trip
go package implements a round-trip pattern for http requests
https://github.com/gregoryv/trip
Last synced: about 1 year ago
JSON representation
go package implements a round-trip pattern for http requests
- Host: GitHub
- URL: https://github.com/gregoryv/trip
- Owner: gregoryv
- License: mit
- Created: 2018-01-08T14:12:29.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-01-12T12:41:37.000Z (over 8 years ago)
- Last Synced: 2025-02-05T07:19:33.385Z (over 1 year ago)
- Language: Go
- Size: 17.6 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/gregoryv/trip)
[](https://codecov.io/gh/gregoryv/trip)
[](https://codeclimate.com/github/gregoryv/trip/maintainability)
[trip](https://godoc.org/github.com/gregoryv/trip) - implements a round-trip pattern for http requests
## Quick start
go get github.com/gregoryv/trip
## The round-trip pattern
A round-trip pattern is basically
1. Prepare trip
2. Execute
3. Optionally parse response
Other descriptions that fit this pattern would be remote procedure
call(RPC), which http requests are of sorts. With this package the
steps inbetween are abstracted and you get to write more go idomatic
code. I designed this package in a way that resembles `os.exec`
Prepare trip
request := http.NewRequest("GET", "/", nil)
cmd := trip.NewCommand(request)
Do the trip
statusCode, err := cmd.Run()
// or if you want the response parsed
err := cmd.Output(&model)
## When to use
When you talk to remote services and need to only vary parts of the
flow, ie. an API has changed and requires a new parameter, then you
only have to modify the part that builds your request. Hopefully it's
easier to maintain a backwards compatible client for a constantly
changing remote service.