Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/instantan/web

Build robust web applications with pure Go. No external dependencies, just the power of the standard library.
https://github.com/instantan/web

openapi openapi3 redoc scalar swagger typescript-generator

Last synced: 20 days ago
JSON representation

Build robust web applications with pure Go. No external dependencies, just the power of the standard library.

Awesome Lists containing this project

README

        

Web: The Zero-Dependency Go Web Framework

> Warning: This package is currently (not even) in alpha, not really tested yet and should not be used yet

## Todos
- Find a good api for defining sockets -> maybe dont implement sockets
- Content type handling in generated api

## Key Features
- **Zero Dependencies**: Built entirely on Go's standard library. No external packages required.
- **OpenAPI Integration**: Automatically generate OpenAPI specifications for your APIs, enhancing documentation and interoperability.
- **TypeScript API generator**: Automatically generate TypeScript definitions for your Go APIs, ensuring type safety across your full-stack application.

## Quick Start

Install with:
```bash
go get github.com/Instantan/web
```

Example usage:
```go
package main

import (
"log"
"net/http"
"github.com/Instantan/web"
)

func main() {
w := web.NewWeb()

w.Info(web.Info{
Title: "MyProject",
Version: "0.0.1",
})

w.OpenApi(web.OpenApi{
DocPath: "/api/doc.json",
UiPath: "/api/doc",
UiVariant: "scalar",
})

w.Api(web.Api{
Method: http.MethodGet,
Path: "/hello/{name}",
Parameter: web.Parameter{
Path: web.Path{
"name": web.PathParam{
Description: "The name to say hello to",
Value: "world",
},
},
},
Responses: web.Responses{
StatusOK: "Hello World",
},
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello " + r.PathValue("name")))
}),
})

log.Println("Server listening on :8080")
log.Println("Visit http://localhost:8080/api/doc to view the documentation")
if err := http.ListenAndServe(":8080", w.Server()); err != nil {
panic(err)
}
}
```

---

[![Go Report Card](https://goreportcard.com/badge/github.com/Instantan/web)](https://goreportcard.com/report/github.com/Instantan/web)