Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom status code #176

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions examples/consul/config.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ protobuffers = ["./schemas/*.proto"]
include = ["flow.hcl"]

http {
address = ":8080"
address = ":8080"
}

discovery "consul" {
address = "http://localhost:8500"
address = "http://localhost:8500"
}

// It's also possible to define a named discovery server client.
Expand All @@ -22,18 +22,18 @@ discovery "consul" {
// }

service "com.semaphore" "awesome-dogs" {
transport = "http"
codec = "json"
host = "http://awesome-dogs"
resolver = "consul"
transport = "http"
codec = "json"
host = "http://awesome-dogs"
resolver = "consul"

method "List" {
response = "com.semaphore.Dogs"
request = "com.semaphore.Void"
method "List" {
response = "com.semaphore.Dogs"
request = "com.semaphore.Void"

options {
endpoint = "/"
method = "GET"
options {
endpoint = "/"
method = "GET"
}
}
}
}
20 changes: 11 additions & 9 deletions examples/consul/flow.hcl
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
endpoint "ListAwesomeDogs" "http" {
endpoint = "/"
method = "GET"
codec = "json"
endpoint = "/"
method = "GET"
codec = "json"
}

flow "ListAwesomeDogs" {
resource "list" {
request "com.semaphore.awesome-dogs" "List" {}
}
resource "list" {
request "com.semaphore.awesome-dogs" "List" {}
}

output "com.semaphore.Dogs" {
dogs = "{{ list:dogs }}"
}
output {
payload "com.semaphore.Dogs" {
dogs = "{{ list:dogs }}"
}
}
}
37 changes: 24 additions & 13 deletions examples/custom-functions/flow.hcl
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
endpoint "FetchLatestProject" "http" {
endpoint = "/"
method = "GET"
codec = "json"
method = "GET"
codec = "json"
}

error "proto.Error" {
value = "some message"
error {
status = 400

payload "proto.Error" {
value = "some message"
}
}

flow "FetchLatestProject" {
input "proto.Query" {
input {
header = ["Authorization"]

payload "proto.Query" {}
}

error "proto.Unauthorized" {
message = "{{ error:message }}"
status = "{{ error:status }}"
error {
// TODO: allow reference
status = 401 // "{{ error:status }}"

payload "proto.Unauthorized" {
message = "{{ error:message }}"
}
}

on_error {
status = 401
status = 401
message = "on error message"
}

Expand All @@ -40,13 +49,15 @@ flow "FetchLatestProject" {
}
}

output "proto.Item" {
output {
header {
Username = "{{ user:username }}"
}

id = "{{ query:id }}"
title = "{{ query:title }}"
completed = "{{ query:completed }}"
payload "proto.Item" {
id = "{{ query:id }}"
title = "{{ query:title }}"
completed = "{{ query:completed }}"
}
}
}
58 changes: 41 additions & 17 deletions examples/error-handling/flow.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ endpoint "GlobalHandleError" "http" {
codec = "json"
}

error "proto.Error" {
message = "{{ error:message }}"
status = "{{ error:status }}"
error {
status = 400 // "{{ error:status }}"

payload "proto.Error" {
message = "{{ error:message }}"
}
}

flow "GlobalHandleError" {
input "proto.Empty" {}
input {
payload "proto.Empty" {}
}

resource "query" {
request "proto.Service" "ThrowError" {
Expand All @@ -34,7 +39,10 @@ flow "GlobalHandleError" {
}
}

output "proto.Empty" {}
output {
// TODO: omit empty payload
payload "proto.Empty" {}
}
}

endpoint "FlowHandleError" "http" {
Expand All @@ -44,15 +52,20 @@ endpoint "FlowHandleError" "http" {
}

flow "FlowHandleError" {
input "proto.Empty" {}
input {
payload "proto.Empty" {}
}

error "proto.Error" {
message = "{{ error:message }}"
status = "{{ error:status }}"
error {
status = 401 // "{{ error:status }}"

payload "proto.Error" {
message = "{{ error:message }}"
}
}

on_error {
status = 401
status = 402
message = "flow error message"
}

Expand All @@ -61,7 +74,10 @@ flow "FlowHandleError" {
}
}

output "proto.Empty" {}
output {
// TODO: omit empty payload
payload "proto.Empty" {}
}
}

endpoint "NodeHandleError" "http" {
Expand All @@ -71,22 +87,30 @@ endpoint "NodeHandleError" "http" {
}

flow "NodeHandleError" {
input "proto.Empty" {}
input {
payload "proto.Empty" {}
}

resource "query" {
request "proto.Service" "ThrowError" {
}

error "proto.Error" {
message = "{{ error:message }}"
status = "{{ error:status }}"
error {
status = 400

payload "proto.Error" {
message = "{{ error:message }}"
}
}

on_error {
status = 401
status = 403
message = "node error message"
}
}

output "proto.Empty" {}
output {
// TODO: omit empty payload
payload "proto.Empty" {}
}
}
2 changes: 1 addition & 1 deletion examples/functions/config.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ protobuffers = ["./proto/*.proto"]
include = ["flow.hcl"]

http {
address = ":8080"
address = ":8080"
}

services {}
60 changes: 36 additions & 24 deletions examples/functions/flow.hcl
Original file line number Diff line number Diff line change
@@ -1,41 +1,53 @@
endpoint "string" "http" {
endpoint = "/string"
method = "POST"
codec = "json"
endpoint = "/string"
method = "POST"
codec = "json"
}

flow "string" {
input "com.semaphore.GreetRequest" {}

output "com.semaphore.GenericResponse" {
message = "{{ sprintf('Hey %s! What is that %s?', input:name, input:subject) }}"
}
input {
payload "com.semaphore.GreetRequest" {}
}

output {
payload "com.semaphore.GenericResponse" {
message = "{{ sprintf('Hey %s! What is that %s?', input:name, input:subject) }}"
}
}
}

endpoint "numeric" "http" {
endpoint = "/numeric"
method = "POST"
codec = "json"
endpoint = "/numeric"
method = "POST"
codec = "json"
}

flow "numeric" {
input "com.semaphore.AgeRequest" {}

output "com.semaphore.GenericResponse" {
message = "{{ sprintf('Hey %s! I know you are %d years old!', input:name, input:age) }}"
}
input {
payload "com.semaphore.AgeRequest" {}
}

output {
payload "com.semaphore.GenericResponse" {
message = "{{ sprintf('Hey %s! I know you are %d years old!', input:name, input:age) }}"
}
}
}

endpoint "json" "http" {
endpoint = "/json"
method = "POST"
codec = "json"
endpoint = "/json"
method = "POST"
codec = "json"
}

flow "json" {
input "com.semaphore.MsgRequest" {}

output "com.semaphore.GenericResponse" {
message = "{{ sprintf('Hey %s! We have got your personal info in JSON: %json!', input:name, input:info) }}"
}
input {
payload "com.semaphore.MsgRequest" {}
}

output {
payload "com.semaphore.GenericResponse" {
message = "{{ sprintf('Hey %s! We have got your personal info in JSON: %json!', input:name, input:info) }}"
}
}
}
30 changes: 19 additions & 11 deletions examples/graphql/flow.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ endpoint "latest_todo" "graphql" {
}

flow "latest_todo" {
input "com.semaphore.Empty" {}
input {
payload "com.semaphore.Empty" {}
}

resource "query" {
request "com.semaphore.Todo" "First" {
}
}

output "com.semaphore.Item" {
id = "{{ query:id }}"
title = "{{ query:title }}"
completed = "{{ query:completed }}"
output {
payload "com.semaphore.Item" {
id = "{{ query:id }}"
title = "{{ query:title }}"
completed = "{{ query:completed }}"
}
}
}

Expand All @@ -26,7 +30,9 @@ endpoint "todo" "graphql" {
}

flow "todo" {
input "com.semaphore.Query" {}
input {
payload "com.semaphore.Query" {}
}

resource "query" {
request "com.semaphore.Todo" "Get" {
Expand All @@ -36,10 +42,12 @@ flow "todo" {
}
}

output "com.semaphore.Item" {
id = "{{ query:id }}"
userId = "{{ query:userId }}"
title = "{{ query:title }}"
completed = "{{ query:completed }}"
output {
payload "com.semaphore.Item" {
id = "{{ query:id }}"
userId = "{{ query:userId }}"
title = "{{ query:title }}"
completed = "{{ query:completed }}"
}
}
}
Loading