Skip to content
/ web Public

Open source backend framework for building dynamic web sites and mobile applications.

License

Notifications You must be signed in to change notification settings

zhgo/web

Repository files navigation

Package for build web backend server

This is a special API server based on http protocol, only accept POST method, all incoming parameters are stored in the request body and must be JSON format, and can only output data in JSON format.

It's not like RESTful that allows GET, POST, PUT, DELETE and so on, it only allows POST methods.

Build Status Coverage Status GoDoc License

Feature

  • Standalone server
  • Only support POST method
  • Only support JSON format
  • Support multiple ports
  • No custom routers
  • One action is a struct, not a struct method

Example

package passport

import (
    "github.com/zhgo/web"
)

type UserList struct {
    
}

// This is only a example and keep it empty
func (c *UserList) Load(module, action string, r *http.Request) error {
    return nil
}

func (c *UserList) Render() web.ActionResult {
    d := map[string]string{"name": "John", "gender": "male"}
    list := []map[string]string{d}
    return web.Done(list)
}

func init() {
    web.NewHandle(new(UserList))
}

The UserList is action. Now you can write a main function call action above:

package main

import (
    "github.com/zhgo/web"
    _ "passport" 
)

func main() {
    web.Start()
}

Then open browser and type this words in address input box:

http://localhost/Passport/UserList

[{"name": "John", "gender": "male"}]

This is only a demo, not for production. If you want to use in project, Careful planning module first.

Remember HTTP protocol, POST method and JSON format.

Copyright

Copyright 2015 The zhgo Authors. All rights reserved.

Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

About

Open source backend framework for building dynamic web sites and mobile applications.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages