Skip to content

nokia/restful

Folders and files

NameName
Last commit message
Last commit date

Latest commit

72e5414 · Oct 25, 2024
Sep 25, 2024
May 3, 2024
Sep 3, 2024
May 17, 2021
May 3, 2024
Jun 1, 2023
Oct 11, 2022
Jan 24, 2024
Oct 11, 2024
Sep 4, 2024
Sep 25, 2024
Jul 14, 2022
Jul 14, 2022
Jan 24, 2024
Jan 24, 2024
Sep 3, 2024
Jan 24, 2024
Sep 3, 2024
Jan 24, 2024
Sep 25, 2024
May 24, 2024
May 24, 2024
Apr 5, 2024
Jan 24, 2024
May 3, 2024
Jan 24, 2024
Sep 3, 2024
Jan 24, 2024
Sep 25, 2024
Feb 1, 2024
Sep 4, 2024
Sep 4, 2024
Jan 24, 2024
Jan 24, 2024
Jan 24, 2024
Sep 4, 2024
Jan 24, 2024
Sep 4, 2024
Jul 7, 2021
Oct 25, 2024
Sep 3, 2024
Sep 3, 2024
Sep 4, 2024
Oct 11, 2024
Oct 11, 2024
Oct 9, 2024
Oct 9, 2024
Jan 24, 2024
May 24, 2024
May 24, 2024
Jan 24, 2024
Jan 24, 2024

Repository files navigation

RESTful

Quick introduction

This Go package is a powerful extension of standard Go HTTP server and client libraries. It lets you handle HTTP+JSON without any extra code.

Reference.

Lambda server

You receive and respond with data structures.

type reqData struct{
    Num int `json:"num" validate:"lt=1000000"`
}

type respData struct{
    Number int `json:"number"`
}

func create(ctx context.Context, req *reqData) (*respData, error) {
    // You use data structures directly, without marshalling and unmarshalling.
    resp := respData{Number: reqData.Num}
    return &respData, nil
}

func main() {
    restful.HandleFunc("/user/v1", create).Methods(http.MethodPost)
    restful.Start()
}

RESTful client

You send and receive data structures.

location, err := restful.Post(ctx, "https://example.com", &reqData, &respData)

Details

  • Lambda server Focus on business logic. It is a modern variant of an HTTP server.
  • RESTful server An underlying HTTP server of Lambda. An HTTP server with goodies. Besides helper functions for receiving and sending JSON data and it can do logging. Router is based on Gorilla/Mux, offering similar services.
  • RESTful client Sending GET, POST (and receiving Location), PUT, PATCH or DELETE requests and receiving their responses. And numerous other helper functions.
  • Tracing information is propagated in context, received in Lambda and used in client request. That is all done without any extra coding on your side. Based on OpenTelemetry.
  • Monitor is a convenient middleware solution to pre-process requests and post-process responses. Pre and post hooks can be used for whatever you want, such as adding Prometheus counters on router level, without littering your business logic.
  • Error is a Go error object containing HTTP status code besides traditional error.

Trace context and error are the glue between Lambda and Client. That is why they form a module together.

Principles

  • Simple, intuitive, Go-ish.
  • Similar to Go's built-in http package, with some advanced router inherited from Gorilla/Mux project.
  • Powerful HTTP+JSON framework reducing development costs while improving quality.
  • Have quite many goodies needed on developing complex applications.