example/

directory
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2018 License: MIT

README

Example

This example covers the creation of a service for https://jsonplaceholder.typicode.com/ public test API with the following functions:

  • Get an entry by ID
  • List all entries
  • Create a new entry
  • Delete an entry by ID

Step-by-step

Install httpclient
go get -u github.com/postfinance/httpclient/cmd/httpclient-gen-go
Define a service interface
// PostService interface defines service methods
type PostService interface {
	Get(context.Context, int) (*Post, *http.Response, error)
	List(context.Context) ([]Post, *http.Response, error)
	Create(context.Context, *Post) (*Post, *http.Response, error)
	Delete(context.Context, int) (*http.Response, error)
}
Implement the interface

See jsonplaceholder.go

Generate the httpclient code
httpclient-gen-go -path ./jsonplaceholder -package jsonplaceholder -out ./jsonplaceholder/httpclient.go
Run tests
cd jsonplaceholder
go test -v
Usage

See jsonplaceholder_test.go

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL