use-as-library

command
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

README

Use As Library

This example shows how a subset of babyapi features can be used as a library rather than a full framework. The more interesting features that can be used this way are:

  • Use babyapi.Handler with stdlib HTTP server to simplify response rendering
  • Use babyapi.ReadRequestBodyAndDo as an HTTP handler that automatically reads the request body and responds based on the generic parameter
  • Use babyapi/html package to simplify responding with HTML templates
  • Use the generic babyapi.MakeRequest function to make a request to the server

Run the application:

go run main.go

Test the POST handler with curl:

curl localhost:8080/create-data -H "Content-Type: application/json" -d '{"Data": {"a":"b"}}'

Visit the other endpoints in the browser:

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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