rest

command module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

README

Rest

ci codecov docker chat

Rest serves a fully RESTful API from any SQL database, PostgreSQL, MySQL, and SQLite are supported for now.

Visit https://rest-go.com for the full documentation, examples, and guides.

Getting Started

Start with Docker

run the server and connect to an existing database

# connect to postgres
docker run -p 3000:3000 restgo/rest -db.url "postgres://user:passwd@localhost:5432/db"

# connect to sqlite file with volume
docker run -p 3000:3000 -v $(pwd):/data restgo/rest -db.url "sqlite:///data/my.db"
Use API

Assume there is a todos table in the database with id, and title fields:

# Create a todo item
curl -XPOST "localhost:3000/todos" -d '{"title": "setup api server", "done": false}'

# Read
curl -XGET "localhost:3000/todos/1"

# Update
curl -XPUT "localhost:3000/todos/1" -d '{"title": "setup api server", "done": true}'

# Delete
curl -XDELETE "localhost:3000/todos/1"

Use the binary

Precompiled binaries

Precompiled binaries for released versions are available on the Releases page, download it to your local machine, and running it directly is the fastest way to use Rest.

Go install

If you are familiar with Golang, you can use go install

go install github.com/rest-go/rest
Run server
rest -db.url "mysql://username:password@tcp(localhost:3306)/db"

Use it as a Go library

It also works to embed the rest server into an existing Go HTTP server

go get github.com/rest-go/rest
package main

import (
	"log"
	"net/http"

	"github.com/rest-go/rest/pkg/server"
)

func main() {
	h := server.New(&server.DBConfig{URL: "sqlite://my.db"}, server.Prefix("/admin"))
	http.Handle("/admin/", h)
	log.Fatal(http.ListenAndServe(":3001", nil))
}

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
examples
pkg
auth
package auth provide restful interface for authentication
package auth provide restful interface for authentication
jsonutil
package json handle all http json operations like decode input or output json response
package json handle all http json operations like decode input or output json response
log
server
package handler provide RESTFul interfaces for all database tables
package handler provide RESTFul interfaces for all database tables
sql
package sqlx provides a is a wrap of golang database/sql package to hide logic for different drivers, the three main functions of this package are: 1.
package sqlx provides a is a wrap of golang database/sql package to hide logic for different drivers, the three main functions of this package are: 1.

Jump to

Keyboard shortcuts

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