api

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2022 License: BSD-3-Clause Imports: 6 Imported by: 0

README

API services

This folder contains the description and implementation of the handlers of the APIs.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SampleDesc desc.ServiceDescFunc = func() *desc.Service {
	return desc.NewService("SampleService").
		SetEncoding(ronykit.JSON).
		AddError(dto.Err(http.StatusBadRequest, "INPUT")).
		AddContract(
			desc.NewContract().
				SetInput(&dto.EchoRequest{}).
				SetOutput(&dto.EchoResponse{}).
				NamedSelector("EchoGET", fasthttp.REST(http.MethodGet, "/echo/:randomID")).
				NamedSelector("EchoPOST", fasthttp.REST(http.MethodPost, "/echo-post")).
				NamedSelector("EchoRPC", fasthttp.RPC("echoRequest")).
				AddModifier(func(envelope ronykit.Envelope) {
					envelope.SetHdr("X-Custom-Header", "justForTestingModifier")
				}).
				SetHandler(EchoHandler),
		).
		AddContract(
			desc.NewContract().
				SetName("Sum").
				SetInput(&dto.SumRequest{}).
				SetOutput(&dto.SumResponse{}).
				NamedSelector("Sum1", fasthttp.REST(http.MethodGet, "/sum/:val1/:val2")).
				NamedSelector("Sum2", fasthttp.REST(http.MethodPost, "/sum")).
				SetHandler(SumHandler),
		).
		AddContract(
			desc.NewContract().
				SetInput(&dto.SumRequest{}).
				SetOutput(&dto.SumResponse{}).
				NamedSelector("SumRedirect", fasthttp.REST(http.MethodGet, "/sum-redirect/:val1/:val2")).
				Selector(fasthttp.REST(http.MethodPost, "/sum-redirect")).
				SetHandler(SumRedirectHandler),
		).
		AddContract(
			desc.NewContract().
				SetInput(&dto.RedirectRequest{}).
				Selector(fasthttp.REST(http.MethodGet, "/redirect")).
				SetHandler(Redirect),
		).
		AddContract(
			desc.NewContract().
				SetInput(ronykit.RawMessage{}).
				SetOutput(ronykit.RawMessage{}).
				Selector(fasthttp.REST(http.MethodPost, "/raw_echo")).
				SetHandler(RawEchoHandler),
		)
}

Functions

func EchoHandler

func EchoHandler(ctx *ronykit.Context)

func RawEchoHandler added in v0.7.1

func RawEchoHandler(ctx *ronykit.Context)

func Redirect

func Redirect(ctx *ronykit.Context)

func SumHandler

func SumHandler(ctx *ronykit.Context)

func SumRedirectHandler

func SumRedirectHandler(ctx *ronykit.Context)

Types

This section is empty.

Jump to

Keyboard shortcuts

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