crookse / go-drash

A REST microframework for Go built on top of fasthttp.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Drash

A REST microframework for Go built on top of fasthttp.

Quickstart

  1. Create your resource.
// File: /path/to/your/project/resources/home_resource.go

package resources

import (
	"github.com/drashland/go-drash/http"
)

func HomeResource() http.Resource {
	return http.Resource{

		Uris: []string{
			"/",
		},

		GET: func (r *http.Request) http.Response {
			r.Response.Body = "Hello, World! Go + Drash is cool!"
			return r.Response
		},
	}
}
  1. Create your app.
// File: /path/to/your/project/app.go

package main

import (
	"fmt"

	"./resources"
	"github.com/drashland/go-drash/http"
)

func main() {
	server := http.Server{
		ResponseContentType: "application/json",
		Resources: []func() http.Resource{
			resources.HomeResource,
		},
	}

	options := http.ServerOptions{
		Hostname: "localhost",
		Port: 1997,
	}

	fmt.Println(fmt.Sprintf(
		"Server started at http://%s:%d", options.Hostname, options.Port,
	))

	server.Run(options)
}
  1. Run your app.
$ go get
$ go run app.go
  1. Make a request.
$ curl localhost:1997
Hello World! Go + Drash is cool!

About

A REST microframework for Go built on top of fasthttp.


Languages

Language:Go 100.0%