Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gopher1980/dynql
DynQL
https://github.com/gopher1980/dynql
api api-rest go golang graphql json json-api json-patch json-schema jsona jsonpath query rest transformer
Last synced: about 1 month ago
JSON representation
DynQL
- Host: GitHub
- URL: https://github.com/gopher1980/dynql
- Owner: gopher1980
- License: apache-2.0
- Created: 2019-09-10T21:11:45.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-09-20T18:03:38.000Z (over 5 years ago)
- Last Synced: 2024-11-14T16:11:54.014Z (2 months ago)
- Topics: api, api-rest, go, golang, graphql, json, json-api, json-patch, json-schema, jsona, jsonpath, query, rest, transformer
- Language: Go
- Homepage:
- Size: 36.1 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dynql
DynQL is has one enpoint for query and tranform the Entities.
Example
POST -> 127.0.0.1:9090/dqlInput:
```json
{
"query1": {
"method": "demo",
"input": {
"name": "Pedro Martinez",
"age": 59,
"position": {
"name": "manager"
}
},
"output": {
"first_name": "$.name",
"age": "$.age",
"level": "$.position.name"
}
},
"query2": {
"method": "demo",
"input": {
"name": "Marcela Perez",
"age": 31
}
}
}
```Output
```json
{
"query1": {
"age": 59,
"first_name": "Pedro Martinez",
"level": "manager"
},
"query2": {
"age": 31,
"name": "Marcela Perez",
"position": {
"name": ""
}
}
}
``````go
package mainimport (
"github.com/gopher1980/dynql"
"github.com/gorilla/mux"
"log"
"net/http"
)
type Position struct {
Name string `json:"name"`
}
type Persona struct {
Name string `json:"name"`
Age int `json:"age"`
Position Position `json:"position"`
}
func demo(name string, ptr interface{}, r *http.Request,payload interface{}, parent interface{}) interface{} {
p := ptr.(*Persona)
return p}
func main() {
dql := dynql.NewDQL()
dql.Put("demo", demo, Persona{})
r := mux.NewRouter()
r.HandleFunc("/dql", dql.Run).Methods(http.MethodPost)
http.Handle("/", r)
log.Fatal(http.ListenAndServe(":9090", nil))
}
```Example without strictic struct:
```go
package mainimport (
"github.com/gopher1980/dynql"
"github.com/gorilla/mux"
"log"
"net/http"
)func demo(name string, ptr interface{}, r *http.Request,payload interface{}, parent interface{}) interface{} {
return ptr}
func main() {
dql := dynql.NewDQL()
dql.Put("demo", demo, make(map[string]interface{}))
r := mux.NewRouter()
r.HandleFunc("/dql", dql.Run).Methods(http.MethodPost)
http.Handle("/", r)
log.Fatal(http.ListenAndServe(":9090", nil))
}```