https://github.com/derveloper/kalfor
Combine multiple HTTP GET requests into a single POST. The most simplest alternative to Facebook's GraphQL and Netflix Falcor.
https://github.com/derveloper/kalfor
Last synced: 8 months ago
JSON representation
Combine multiple HTTP GET requests into a single POST. The most simplest alternative to Facebook's GraphQL and Netflix Falcor.
- Host: GitHub
- URL: https://github.com/derveloper/kalfor
- Owner: derveloper
- License: apache-2.0
- Archived: true
- Created: 2016-07-03T12:02:59.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2021-02-18T21:35:17.000Z (over 5 years ago)
- Last Synced: 2024-10-06T23:02:54.617Z (over 1 year ago)
- Language: Kotlin
- Homepage:
- Size: 24.8 MB
- Stars: 10
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DISCONTINUED
# kalfor
[](https://maven-badges.herokuapp.com/maven-central/cc.vileda.kalfor/kalfor-library)
[](https://travis-ci.org/derveloper/kalfor)
[](https://github.com/Aaronepower/tokei)
[](https://codecov.io/gh/derveloper/kalfor)
[](https://www.versioneye.com/user/projects/591f41b98dcc41003af21ec7)
[](https://github.com/vert-x3/vertx-awesome#microservices)
kalfor is a HTTP multiplexer microservice
## what?
kalfor transforms a single HTTP `POST` request to multiple parallel HTTP `GET` requests to a given HTTP backend
which then are combined and send back to the client in a single JSON response.
## why
while developing frontends for REST APIs you'll face performance problems because you have to make too many requests.
with kalfor you can combine all your REST Calls into a single `POST` request.
kalfor will fetch each endpoint in parallel for you and and respond all API responses in a single JSON to you.
## demo instance
You can find the demo instance at https://kalfor.app.vileda.cc/combine
### try it yourself
```
$ curl -H'Content-Type: application/json' \
--data '[{"proxyBaseUrl":"https://api.github.com", "proxyRequests":[{"path":"/", "key":"github"}]},'\
'{"proxyBaseUrl":"https://api.spotify.com", "proxyRequests":[{"path":"/v1", "key":"spotify"}]}]' \
'https://kalfor.app.vileda.cc/combine'
```
## api
### request schema
The schema for a kalfor request
```javascript
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "array",
"items": {
"type": "object",
"properties": {
"proxyBaseUrl": {
"type": "string"
},
"headers": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"value": {
"type": "string"
}
},
"required": [
"name",
"value"
]
}
},
"proxyRequests": {
"type": "array",
"items": {
"type": "object",
"properties": {
"path": {
"type": "string"
},
"key": {
"type": "string"
}
},
"required": [
"path",
"key"
]
}
}
},
"required": [
"proxyBaseUrl",
"proxyRequests"
]
}
}
```
A request with all current features
```javascript
[
{
"proxyBaseUrl": "https://api.github.com",
"proxyRequests": [
{
"path": "/",
"key": "github"
}
]
},
{
"proxyBaseUrl": "https://api.spotify.com",
"headers": [
{
"name": "Authorization",
"value": "Bearer "
}
],
"proxyRequests": [
{
"path": "/v1/me",
"key": "spotify"
}
]
}
]
```
## installation
### maven
#### Add kalfor dependency
```xml
cc.vileda.kalfor
kalfor-library
4.0.0
```
### gradle
#### Add kalfor dependency
```groovy
compile 'cc.vileda.kalfor:kalfor-library:4.0.0'
```
## Use it
### create your http server
```kotlin
fun main(args: Array) {
print("starting kalfor server...")
embeddedServer(Netty, 8080) {
routing {
post("/combine") {
val json = call.request.receive(String::class)
val resp = validateSchema(json)
.fold({
Gson().toJson(kalforPost(Gson()
.fromJson>(json)))
}, {
it.printStackTrace()
it.message!!
})
call.respondText(resp)
}
}
}.start(wait = true)
}
```
### combine
```
$ curl -H'Content-Type: application/json' \
--data '[{"proxyBaseUrl":"https://api.github.com", "proxyRequests":[{"path":"/", "key":"github"}]},'\
'{"proxyBaseUrl":"https://api.sipgate.com", "proxyRequests":[{"path":"/v1", "key":"sipgate"}]}]' \
'http://localhost:8080/combine'
{
"github": {
"current_user_url" : ...,
...
},
"sipgate" : {
"authorizationOauthClientsSecretUrl" : ...,
...
}
}
```
#### headers
kalfor is able to send specific headers to each backend. Just provide a list of headers in your request JSON
```
$ curl -H'Content-Type: application/json' \
--data '[{"proxyBaseUrl":"https://api.github.com", "proxyRequests":[{"path":"/", "key":"github"}]},'\
'{"proxyBaseUrl":"https://api.spotify.com", "headers":[{"name":"Authorization", "value": "Bearer "}], '\
'"proxyRequests":[{"path":"/v1/me", "key":"spotify"}]}]' \
'http://localhost:8080/combine'
```
## license
```
Copyright 2016 Tristan Leo
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```