httpsimple

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2021 License: MIT Imports: 15 Imported by: 0

README

HTTP Simple for Go

HTTP Simple Server

AWS Lambda Manual Setup
  • AWS Lambda Function Configuration
    1. Create AWS Lambda function
    2. Set SimpleServer.HttpEngine to awslambda, e.g. using environment variable
    3. Set Handler to main
  • API Gateway Configuration
    1. Create "REST" API
    2. Select "New API"
    3. Select "Actions" > "Create Resource"
    4. Click "Configure as proxy resource"
    5. Use Resource Path {proxy+}
    6. Click "Enable API Gateway CORS"
    7. Click "Create Resource"
    8. Leave "Integration Type" as "Lambda Function Proxy"
    9. In "Lambda Function", paste in your Lamda ARN
  1. Click "Deploy API" and create stage if necessary
  2. Test with cURL against Stage Invoke URL
  • API Gateway API Key
    1. Create API Key
    2. Create Usage Plan
    3. Add API Stage by Selecting API Gateway, Stage, and clicking checkmark icon.
    4. Click "Next".
    5. Add API Key, click checkmark icon, click "Done"
    6. Click on API Gateway {proxy+} endpoint, click on ANY
    7. Click on "Method Request"
    8. Click edit icon by "API Key Required", change to true, click checkmark icon
    9. Select "Deploy API"
  1. Test with cURL and X-API-Key header

Documentation

Index

Constants

View Source
const (
	EngineAwsLambda = "awslambda"
	EngineNetHttp   = "nethttp"
	EngineFastHttp  = "fasthttp"
)

Variables

This section is empty.

Functions

func Do added in v0.0.23

func Do(req SimpleRequest) (*http.Response, error)

func HandleTestAnyEngine added in v0.0.5

func HandleTestAnyEngine(aRes anyhttp.Response, aReq anyhttp.Request)

func HandleTestFastHTTP added in v0.0.5

func HandleTestFastHTTP(ctx *fasthttp.RequestCtx)

func HandleTestNetHTTP added in v0.0.5

func HandleTestNetHTTP(res http.ResponseWriter, req *http.Request)

func Serve

func Serve(svc SimpleServer)

Types

type Handler added in v0.26.0

type Handler interface {
	HandleNetHTTP(res http.ResponseWriter, req *http.Request)
	HandleFastHTTP(ctx *fasthttp.RequestCtx)
	HandleAnyHTTP(aRes anyhttp.Response, aReq anyhttp.Request)
}

type SimpleClient

type SimpleClient struct {
	BaseURL    string
	HTTPClient *http.Client
}

SimpleClient provides a simple interface to making HTTP requests using `net/http`.

func NewSimpleClient

func NewSimpleClient(httpClient *http.Client, baseURL string) SimpleClient

func (*SimpleClient) Do

func (sc *SimpleClient) Do(req SimpleRequest) (*http.Response, error)

func (*SimpleClient) DoJSON added in v0.0.7

func (sc *SimpleClient) DoJSON(req SimpleRequest, resBody interface{}) ([]byte, *http.Response, error)

func (*SimpleClient) Get

func (sc *SimpleClient) Get(reqURL string) (*http.Response, error)

type SimpleRequest

type SimpleRequest struct {
	Method  string
	URL     string
	Query   map[string][]string
	Headers map[string][]string
	Body    interface{}
	IsJSON  bool
}

func (*SimpleRequest) BodyBytes

func (req *SimpleRequest) BodyBytes() ([]byte, error)

func (*SimpleRequest) Inflate

func (req *SimpleRequest) Inflate()

type SimpleServer

type SimpleServer interface {
	PortInt() int
	HttpEngine() string
	Router() http.Handler
	RouterFast() *fasthttprouter.Router
}

type TestResponse added in v0.0.5

type TestResponse struct {
	Command    string    `json:"command"`
	RequestURL string    `json:"requestURL"`
	Time       time.Time `json:"time"`
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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