-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#40 httpsupport
- Loading branch information
Showing
14 changed files
with
761 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Gateway using File Resource | ||
This recipe is a gateway using the file resource. | ||
|
||
## Installation | ||
* Install [Go](https://golang.org/) | ||
|
||
## Setup | ||
```bash | ||
git clone https://github.com/project-flogo/microgateway | ||
cd microgateway/examples/api/resource-handler/fileResource | ||
``` | ||
|
||
## Testing | ||
|
||
Start the gateway: | ||
```bash | ||
go run main.go | ||
``` | ||
and test below scenario. | ||
|
||
### Request is successful | ||
Run the following command: | ||
```bash | ||
curl --request GET http://localhost:9096/endpoint | ||
``` | ||
|
||
You should see: | ||
```json | ||
{"category":{"id":0,"name":"string"},"id":4,"name":"hc0x3yiw302","photoUrls":["string"],"status":"available","tags":[{"id":0,"name":"string"}]} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/project-flogo/core/engine" | ||
"github.com/project-flogo/microgateway/examples" | ||
) | ||
|
||
func main() { | ||
e, err := examples.FileResourceHandlerExample("file://../../../json/resource-handler/fileResource/resource.json") | ||
if err != nil { | ||
panic(err) | ||
} | ||
engine.RunEngine(e) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Gateway using HTTP Resource | ||
This recipe is a gateway using the HTTP resource. The resource is downloaded from the requested HTTP server | ||
|
||
## Installation | ||
* Install [Go](https://golang.org/) | ||
|
||
## Setup | ||
```bash | ||
git clone https://github.com/project-flogo/microgateway | ||
cd microgateway/examples/api/resource-handler/httpResource | ||
``` | ||
|
||
## Testing | ||
|
||
In terminal start the server first: | ||
```bash | ||
go run main.go -server | ||
``` | ||
|
||
Start the gateway: | ||
```bash | ||
go run main.go | ||
``` | ||
and test below scenario. | ||
|
||
### Request is successful | ||
Run the following command: | ||
```bash | ||
curl --request GET http://localhost:9096/endpoint | ||
``` | ||
|
||
You should see: | ||
```json | ||
{"category":{"id":0,"name":"string"},"id":4,"name":"hc0x3yiw302","photoUrls":["string"],"status":"available","tags":[{"id":0,"name":"string"}]} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"html" | ||
"io/ioutil" | ||
"net/http" | ||
|
||
"github.com/project-flogo/core/engine" | ||
"github.com/project-flogo/microgateway/examples" | ||
) | ||
|
||
var ( | ||
server = flag.Bool("server", false, "run the test server") | ||
) | ||
|
||
const resource = `{ | ||
"name": "Pets", | ||
"steps": [{ | ||
"service": "PetStorePets", | ||
"input": { | ||
"pathParams": "=$.payload.pathParams" | ||
} | ||
}], | ||
"responses": [{ | ||
"error": false, | ||
"output": { | ||
"code": 200, | ||
"data": "=$.PetStorePets.outputs.data" | ||
} | ||
}], | ||
"services": [{ | ||
"name": "PetStorePets", | ||
"description": "Get pets by ID from the petstore", | ||
"ref": "github.com/project-flogo/contrib/activity/rest", | ||
"settings": { | ||
"uri": "http://petstore.swagger.io/v2/pet/:petId", | ||
"method": "GET", | ||
"headers": { | ||
"Accept": "application/json" | ||
} | ||
} | ||
}] | ||
}` | ||
|
||
func main() { | ||
|
||
flag.Parse() | ||
|
||
if *server { | ||
http.HandleFunc("/pets", func(w http.ResponseWriter, r *http.Request) { | ||
fmt.Printf("url: %q\n", html.EscapeString(r.URL.Path)) | ||
defer r.Body.Close() | ||
body, err := ioutil.ReadAll(r.Body) | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Println(string(body)) | ||
w.Header().Set("Content-Type", "application/json") | ||
_, err = w.Write([]byte(resource)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
}) | ||
|
||
err := http.ListenAndServe(":1234", nil) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return | ||
} | ||
|
||
e, err := examples.HTTPResourceHandlerExample() | ||
if err != nil { | ||
panic(err) | ||
} | ||
engine.RunEngine(e) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.