1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-01-05 10:20:53 +02:00
go-micro/plugins/client/http
Jerry 93ba8cd0df
continue fix pre version go get bug that unknown v3.5.1 (#2188)
* 1.fix plugins go get bug.
2.update all mode.
3.add tidy tools

* continue fix pre version go get bug that unknown v3.5.1
2021-06-30 09:24:00 +01:00
..
test update v3 plugins (#2105) 2021-01-20 21:01:10 +00:00
buffer.go add all the plugins 2020-12-26 15:32:45 +00:00
codec.go update v3 plugins (#2105) 2021-01-20 21:01:10 +00:00
go.mod continue fix pre version go get bug that unknown v3.5.1 (#2188) 2021-06-30 09:24:00 +01:00
go.sum 1.fix plugins go get bug. (#2187) 2021-06-30 07:21:03 +01:00
http_test.go fix 404 bug (#2179) 2021-06-16 07:56:41 +01:00
http.go fix 404 bug (#2179) 2021-06-16 07:56:41 +01:00
message.go update v3 plugins (#2105) 2021-01-20 21:01:10 +00:00
README.md update v3 plugins (#2105) 2021-01-20 21:01:10 +00:00
request.go update v3 plugins (#2105) 2021-01-20 21:01:10 +00:00
stream.go update v3 plugins (#2105) 2021-01-20 21:01:10 +00:00

HTTP Client

This plugin is a http client for go-micro.

Overview

The http client wraps net/http to provide a robust go-micro client with service discovery, load balancing and streaming. It complies with the go-micro.Client interface.

Usage

Use directly

import "github.com/asim/go-micro/plugins/client/http"

service := micro.NewService(
	micro.Name("my.service"),
	micro.Client(http.NewClient()),
)

Use with flags

import _ "github.com/asim/go-micro/plugins/client/http"
go run main.go --client=http

Call Service

Assuming you have a http service "my.service" with path "/foo/bar"

// new client
client := http.NewClient()

// create request/response
request := client.NewRequest("my.service", "/foo/bar", protoRequest{})
response := new(protoResponse)

// call service
err := client.Call(context.TODO(), request, response)

Look at http_test.go for detailed use.

Encoding

Default protobuf with content-type application/proto

client.NewRequest("service", "/path", protoRequest{})

Json with content-type application/json

client.NewJsonRequest("service", "/path", jsonRequest{})