GithubHelp home page GithubHelp logo

dragomir-ivanov / rest-layer-sql Goto Github PK

View Code? Open in Web Editor NEW

This project forked from apuigsech/rest-layer-sql

0.0 2.0 0.0 13 KB

This REST Layer resource storage backend stores data in a SQL Database using database/sql.

Go 100.00%

rest-layer-sql's Introduction

Golang REST Layer SQL Storage Handler

This REST Layer resource storage backend stores data in a SQL Database using database/sql.

Usage

import "github.com/apuigsech/rest-layer-sql"

Create a resource storage handler with a given SQL driver, source and table:

h := sqlStorage.NewHandler(DB_DRIVER, DB_SOURCE, DB_TABLE)

Bind this resource storage handled to a resource:

index.Bind("resourceName", resourceSchema, h, resource.DefaultConf)

Supported SQL Drivers

All supported SQL Drivers are listed here

Examples

Run the example:

$ go run example/example.go
2018/12/07 18:29:53 Serving API on http://localhost:8080

You can perform requests using HTTPie.

$ http GET :8080/units
HTTP/1.1 200 OK
Content-Length: 2
Content-Type: application/json
Date: Fri, 07 Dec 2018 17:31:23 GMT
Etag: W/"d41d8cd98f00b204e9800998ecf8427e"
X-Total: 0

[]

$ http POST :8080/units str="foo" int:=0
HTTP/1.1 201 Created
Content-Length: 139
Content-Location: /units/bg5at5bmvban389193a0
Content-Type: application/json
Date: Fri, 07 Dec 2018 17:32:05 GMT
Etag: W/"80b0d96e674f761e87950ccb19bdc279"
Last-Modified: Fri, 07 Dec 2018 17:32:05 GMT

{
    "created": "2018-12-07T18:32:05.290925+01:00",
    "id": "bg5at5bmvban389193a0",
    "int": 0,
    "str": "foo",
    "updated": "2018-12-07T18:32:05.290925+01:00"
}

$ http POST :8080/units str="bar" int:=1
HTTP/1.1 201 Created
Content-Length: 137
Content-Location: /units/bg5at73mvban389193ag
Content-Type: application/json
Date: Fri, 07 Dec 2018 17:32:12 GMT
Etag: W/"8bb72222f5979bc9f9259c0262807667"
Last-Modified: Fri, 07 Dec 2018 17:32:12 GMT

{
    "created": "2018-12-07T18:32:12.08373+01:00",
    "id": "bg5at73mvban389193ag",
    "int": 1,
    "str": "bar",
    "updated": "2018-12-07T18:32:12.08373+01:00"
}

$ http GET :8080/units
HTTP/1.1 200 OK
Content-Length: 365
Content-Type: application/json
Date: Fri, 07 Dec 2018 17:32:44 GMT
Etag: W/"0a320d03fee8e1fb268d3cc48fac391d"
X-Total: 0

[
    {
        "_etag": "80b0d96e674f761e87950ccb19bdc279",
        "created": "2018-12-07T18:32:05.290925+01:00",
        "id": "bg5at5bmvban389193a0",
        "int": 0,
        "str": "foo",
        "updated": "2018-12-07T18:32:05.290925+01:00"
    },
    {
        "_etag": "8bb72222f5979bc9f9259c0262807667",
        "created": "2018-12-07T18:32:12.08373+01:00",
        "id": "bg5at73mvban389193ag",
        "int": 1,
        "str": "bar",
        "updated": "2018-12-07T18:32:12.08373+01:00"
    }
]

rest-layer-sql's People

Contributors

apuigsech avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.