rpc

command
v0.0.0-...-fabbfc5 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

README

RPC API

本示例我们介绍如何使用RPC handler模式的Micro API,以下简称API

该模式下允许我们通过RPC的方式把HTTP请求转发到go-micro微服务上。

需要提醒的是,RPC模式下API只接收POST方式的请求,并且只消费(consume)内容格式content-typeapplication/json或者application/protobuf

使用方法

使用protoc生成go代码

protoc  --go_out=. --micro_out=. proto/rpc.proto

以rpc模式运行API

micro api --handler=rpc --namespace=go.micro.rpc
go run rpc.go

当我们POST请求到 /example/call时,API会将它转成RPC转发到go.micro.rpc.example服务的Example.Call接口上。

curl -H 'Content-Type: application/json' -d '{"name": "小小先"}' "http://localhost:8080/example/call"

同样,POST请求到 /example/foo/bar时,API会将它转成RPC转发到go.micro.api.example服务的Foo.Bar接口上。

curl -H 'Content-Type: application/json' -d '{}' http://localhost:8080/example/foo/bar

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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