Skip to content

Commit

Permalink
fix: use HTTP bindings correctly (#579)
Browse files Browse the repository at this point in the history
  • Loading branch information
KhudaDad414 authored Nov 23, 2023
1 parent 20d7a67 commit 5f5040f
Show file tree
Hide file tree
Showing 20 changed files with 759 additions and 204 deletions.
26 changes: 26 additions & 0 deletions examples/http-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

# HTTP Test Project

## Overview
This project is a test suite for evaluating the HTTP server functionality in the Glee framework. It sets up an HTTP server on port 3000, and upon receiving a POST request, it sends multiple test requests to `https://httpbin.org/` to verify the operational aspects of the server.


### Installation
1. Navigate to the project directory:
```sh
cd examples/http-test
```
3. Install the necessary Node.js packages:
```sh
npm install
```

### Running the Server
1. Start the HTTP server by running:
```sh
npm run dev
```
2. The server will start on `http://localhost:3000`.

### Testing the Server
Send a POST request to `http://localhost:3000` using a tool like cURL or Postman. The server, upon receiving the request, will initiate several test requests to `https://httpbin.org/` and validate the functionality.
139 changes: 139 additions & 0 deletions examples/http-test/asyncapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
asyncapi: 3.0.0
info:
title: Test HTTP in glee using httpbin.org
version: 1.0.0
description: This app is a test app. it will send requests to httpbin.org to see if glee works well with http protocol.
servers:
httpbin.org:
host: 'httpbin.org'
protocol: https
local-trigger:
host: 'localhost:3000'
protocol: http
channels:
TRIGGER:
address: /
servers:
- $ref: '#/servers/local-trigger'
messages:
string:
$ref: "#/components/messages/string"
empty:
$ref: "#/components/messages/empty"
DELETE:
address: /delete
servers:
- $ref: '#/servers/httpbin.org'
GET:
address: /get
servers:
- $ref: '#/servers/httpbin.org'
POST:
address: /post
servers:
- $ref: '#/servers/httpbin.org'
PATCH:
address: /patch
servers:
- $ref: '#/servers/httpbin.org'
PUT:
address: /put
servers:
- $ref: '#/servers/httpbin.org'
operations:
sendTrigger:
action: send
channel:
$ref: "#/channels/TRIGGER"
messages:
- $ref: "#/components/messages/string"
receiveTrigger:
reply:
channel:
$ref: "#/channels/TRIGGER"
messages:
- $ref: "#/components/messages/string"
channel:
$ref: '#/channels/TRIGGER'
action: receive
bindings:
http:
method: POST
sendDELETE:
channel:
$ref: '#/channels/DELETE'
action: send
bindings:
http:
method: DELETE
receiveDELETE:
channel:
$ref: '#/channels/DELETE'
action: receive
sendGET:
channel:
$ref: '#/channels/GET'
action: send
bindings:
http:
method: GET
receiveGET:
channel:
$ref: '#/channels/GET'
action: receive
bindings:
http:
method: GET
sendPOST:
channel:
$ref: '#/channels/POST'
action: send
bindings:
http:
method: POST
receivePOST:
channel:
$ref: '#/channels/POST'
action: receive
sendPATCH:
channel:
$ref: '#/channels/PATCH'
action: send
bindings:
http:
method: PATCH
receivePATCH:
channel:
$ref: '#/channels/PATCH'
action: receive
sendPUT:
channel:
$ref: '#/channels/PUT'
action: send
bindings:
http:
method: PUT
receivePUT:
channel:
$ref: '#/channels/PUT'
action: receive
components:
messages:
string:
bindings:
http:
headers:
type: object
required: ["a", "b"]
properties:
a:
type: string
b:
type: string
payload:
type: string
empty:
payload:
type: "null"
x-remoteServers:
- httpbin.org
28 changes: 28 additions & 0 deletions examples/http-test/docs/asyncapi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Test HTTP in glee using httpbin.org 1.0.0 documentation

This app is a test app. it will send requests to httpbin.org to see if glee works well with http protocol.

## Table of Contents

* [Servers](#servers)
* [httpbin.org](#httpbinorg-server)
* [local-trigger](#local-trigger-server)

## Servers

### `httpbin.org` Server

* URL: `https://httpbin.org/`
* Protocol: `https`



### `local-trigger` Server

* URL: `http://localhost:3000/`
* Protocol: `http`



## Operations

8 changes: 8 additions & 0 deletions examples/http-test/functions/receiveDELETE.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default async function ({ payload }) {
if (!payload.url) {
console.error("DELETE receive failed.")
return
}

console.log("DELETE operation succeded..")
}
8 changes: 8 additions & 0 deletions examples/http-test/functions/receiveGET.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default async function ({ payload }) {
if (!payload.url) {
console.error("GET receive failed.")
return
}

console.log("GET operation succeded..")
}
8 changes: 8 additions & 0 deletions examples/http-test/functions/receivePATCH.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default async function ({ payload }) {
if (!payload.url) {
console.error("PATCH receive failed.")
return
}

console.log("PATCH operation succeded..")
}
7 changes: 7 additions & 0 deletions examples/http-test/functions/receivePOST.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default async function ({ payload }) {
if (!payload.url) {
console.error("POST receive failed.")
return
}
console.log("POST operation succeded..")
}
8 changes: 8 additions & 0 deletions examples/http-test/functions/receivePUT.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default async function ({ payload }) {
if (!payload.url) {
console.error("PUT receive failed.")
return
}

console.log("PUT operation succeded..")
}
30 changes: 30 additions & 0 deletions examples/http-test/functions/receiveTrigger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export default async function (event) {
const server = 'httpbin.org'
return {
reply: [{
payload: "You have successfully triggered the test server..."
}],
send: [
{
server,
channel: "DELETE"
},
{
server,
channel: "GET"
},
{
server,
channel: "POST"
},
{
server,
channel: "PATCH"
},
{
server,
channel: "PUT"
}
],
}
}
Loading

0 comments on commit 5f5040f

Please sign in to comment.