httplive

package module
v1.3.5 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2022 License: MIT Imports: 32 Imported by: 0

README


title: "Rest API designer" version: 1.3.5

HttpLive

Build Status

The HttpLive is a tool for API designers, Proxy, mobile and web application developers to develop and test their applications faster without being dependent on any server or backend applications.

alt text

HttpLive has a built-in user interface. Therefore, you can do all the configurations you need on this UI, and with dynamic URL (Routing) definitions you can specify your own JSON return types for your applications.

You can share the key-value database (httplive.db) with your teammates, easily back up or store it in the any cloud storage.

Load balancing, Round-robin operations can be operated easily with multi-port mode.

With the support of HttpLive you; we can make it more useful without compromising on simple usage and increase the productivity of our development and testing environments.

Features

  1. 2021-12-01 admin api made more easy
    • curl 'http://127.0.0.1:5003/httplive/webcli/api/save?endpoint=/x1' -d '{"close": true}'
    • curl 'http://127.0.0.1:5003/httplive/webcli/api/save?endpoint=/x1' -d '@a.json
    • curl 'http://127.0.0.1:5003/httplive/webcli/api/save?endpoint=/x2&method=GET' -d '{"Status": true}'
  2. 2021-11-18 http://127.0.0.1:5003/echo.json returns user agent string's parsing results[^1]

Installation

go get github.com/bingoohuang/httplive/...

With this command you can add the httplive application to the path you specify in the Go environment. This way you can run the application from the command line.

Make sure your PATH includes the $GOPATH/bin directory so your commands can be easily used with help (-h) flag:

httplive -h

Arguments

--dbpath, -d

Fullpath of the httplive.db with forward slash.

--ports, -p

Hosting ports can be array comma separated string <5003,5004> to host multiple endpoints. First value of the array is the default port.

HttpLive creates a key-value database for the URLs you define. Here the port value is used as a bucket name for the keys. When working with a single port, the data is associated with this port as keys. When you specify multiple ports, the first value of the array is selected as the default port, and the other ports use the data specified for the default port.

For httplive application running with port 5003:

GET/api/guideline/mobiletoken

this key will be stored in the bucket 5003. Therefor if you running app as single port with 5004 you cannot access the keys of 5003 port. You can use multi-port host to overcome this situation.

Compiling the UI into the Go binary

go install -ldflags="-s -w" ./...

Todo

Tests

CI Build Integration.

Simple console to display the information of the incoming request under the UI editor. (WebSocket)

Upload a database file from the web interface.

Watch the video

Resources

Extensions

  1. Dynamic demo config demo
  2. Proxy demo config demo

httpie test

[2020-11-16 23:42:36.476] ❯ http :5003/dynamic/demo name=bingoo
HTTP/1.1 200 OK
Content-Length: 33
Content-Type: application/json; charset=utf-8
Date: Mon, 16 Nov 2020 16:16:51 GMT

{
    "name": "bingoo"
}


[2020-11-17 00:16:51.399] ❯ http :5003/dynamic/demo name=huang
HTTP/1.1 200 OK
Content-Length: 54
Content-Type: application/json; charset=utf-8
Date: Mon, 16 Nov 2020 16:17:15 GMT

{
    "age": 100,
    "name": "huangxxx"
}

gobench test

[2020-11-17 00:19:47.157] ❯ gobench -u http://127.0.0.1:5003/dynamic/demo --method POST -postData '{"name":"huang"}' -p 0
Dispatching 100 goroutines
Waiting for results...
[√] [200] { "name":"huangxxx", "age":100 }..........
Total Requests:                 658917 hits
Successful requests:            658917 hits
Network failed:                 0 hits
Bad requests(!2xx):             0 hits
Successful requests rate:       65873 hits/sec
Read throughput:                11 MiB/sec
Write throughput:               11 MiB/sec
Test time:                      10.002748474s

sleep in mockbin format demo:

  1. httpstat go version

    [ 22:17:49 ] ❯ http  "http://127.0.0.1:5003/mockbin?_hl=conf"
    HTTP/1.1 200 OK
    Content-Length: 55
    Content-Type: application/json; charset=utf-8
    Date: Mon, 14 Dec 2020 03:18:37 GMT
    
    {
        "method": "GET",
        "sleep": "1s",
        "status": 200
    }
    
    [ 22:17:44 ] ❯ httpstat  "http://127.0.0.1:5003/mockbin?_hl=sleep100ms"
    
    Connected to 127.0.0.1:5003
    
    HTTP/1.1 200 OK
    Content-Length: 0
    Content-Type: text/plain; charset=utf-8
    Date: Mon, 14 Dec 2020 03:17:49 GMT
    
    Body discarded
    
    DNS Lookup   TCP Connection   Server Processing   Content Transfer
    [       0ms  |           0ms  |           1102ms  |             0ms  ]
                |                |                   |                  |
        namelookup:0ms            |                   |                  |
                            connect:0ms               |                  |
                                        starttransfer:1102ms           |
                                                                    total:1103ms
    

[^1]:

img.png

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Envs ...
	Envs = EnvVars{}

	// Clients ...
	Clients = make(map[string]*websocket.Conn)
)

Functions

func APIMiddleware

func APIMiddleware(c *gin.Context)

APIMiddleware ...

func ConfigJsMiddleware

func ConfigJsMiddleware(c *gin.Context)

ConfigJsMiddleware ...

func CreateAPIDataModel

func CreateAPIDataModel(ep *process.Endpoint, query bool) *process.APIDataModel

CreateAPIDataModel creates APIDataModel from Endpoint.

func CreateDB

func CreateDB() error

CreateDB ...

func CreateEndpoint

func CreateEndpoint(model process.APIDataModel, old *process.Endpoint) process.Endpoint

CreateEndpoint creates an endpoint from APIDataModel.

func DBDo

func DBDo(f func(dao *Dao) error) error

DBDo executes the f.

func DeleteEndpoint

func DeleteEndpoint(id string) error

DeleteEndpoint ...

func EndpointList

func EndpointList(query bool) []process.APIDataModel

EndpointList ...

func GetEndpoint

func GetEndpoint(id process.ID) (*process.APIDataModel, error)

GetEndpoint ...

func JoinContextPath added in v1.2.0

func JoinContextPath(elem string) string

JoinContextPath joins the context path to elem.

func SaveEndpoint

func SaveEndpoint(model process.APIDataModel) (*process.Endpoint, error)

SaveEndpoint ...

func StaticFileMiddleware

func StaticFileMiddleware(c *gin.Context)

StaticFileMiddleware ...

func SyncAPIRouter added in v1.2.0

func SyncAPIRouter()

SyncAPIRouter ...

func TestAPIRouter added in v1.2.0

func TestAPIRouter(p process.APIDataModel) error

TestAPIRouter ...

Types

type Dao

type Dao struct {
	// contains filtered or unexported fields
}

Dao defines the api to access the database.

func CreateDao

func CreateDao(db *storm.DB) (*Dao, error)

CreateDao creates a dao.

func (*Dao) AddEndpoint

func (d *Dao) AddEndpoint(ep process.Endpoint) uint64

func (*Dao) Backup added in v1.3.5

func (d *Dao) Backup(w http.ResponseWriter, name string)

func (*Dao) DeleteEndpoint

func (d *Dao) DeleteEndpoint(ep process.Endpoint)

func (*Dao) FindByEndpoint

func (d *Dao) FindByEndpoint(endpoint string) *process.Endpoint

func (*Dao) FindEndpoint

func (d *Dao) FindEndpoint(ID uint64) *process.Endpoint

func (*Dao) HasEndpoints added in v1.3.5

func (d *Dao) HasEndpoints() (has bool)

HasEndpoints test if any endpoint exits already.

func (*Dao) ListEndpoints

func (d *Dao) ListEndpoints() (result []process.Endpoint)

func (*Dao) UpdateEndpoint

func (d *Dao) UpdateEndpoint(ep process.Endpoint)

type EnvVars

type EnvVars struct {
	DBFile      string
	DBFullPath  string
	Ports       string // Hosting ports, eg. 5003,5004.
	ContextPath string
	Logging     bool
}

EnvVars ...

func (*EnvVars) Init added in v1.2.0

func (r *EnvVars) Init()

Init initializes the environments.

type WebCliController

type WebCliController struct{}

WebCliController ...

func (WebCliController) Backup

func (ctrl WebCliController) Backup(c *gin.Context, _ backupT)

Backup ...

func (WebCliController) DeleteEndpoint

func (ctrl WebCliController) DeleteEndpoint(c *gin.Context, _ deleteEndpointT)

DeleteEndpoint ...

func (WebCliController) DownloadFile

func (ctrl WebCliController) DownloadFile(c *gin.Context, _ downloadFileT) error

DownloadFile ...

func (WebCliController) Endpoint

func (ctrl WebCliController) Endpoint(c *gin.Context, _ endpointT) (giu.HTTPStatus, interface{}, error)

Endpoint ...

func (WebCliController) Save

func (ctrl WebCliController) Save(c *gin.Context, _ saveT) (giu.HTTPStatus, interface{})

Save 保存body.

func (WebCliController) SaveEndpoint

func (ctrl WebCliController) SaveEndpoint(model process.APIDataModel, c *gin.Context, _ saveEndpointT)

SaveEndpoint 保存路径、方法等变更.

func (WebCliController) Tree

func (ctrl WebCliController) Tree(_ treeT) gin.H

Tree return the api tree.

func (WebCliController) Version added in v1.2.0

func (ctrl WebCliController) Version(_ versionT) gin.H

Version returns version information.

Directories

Path Synopsis
cmd
httplive command
internal
res
pkg
acl
lb

Jump to

Keyboard shortcuts

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