Skip to content
Merged
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
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,17 @@ endpoint: http://localhost:8000/blog/{id} # we can use 'id' here
headers:
- Content-Type: application/json
- Accept: application/json
whitelist-headers:
allow-headers:
- Content-Type
- Accept
```

> [Click here](/learn-more/request-configuration) for full explanation of all parameters that can be used.

- The args parameter allows us to pass in command line arguments. Formatted like `id=2`
- Method can be any HTTP method
- Endpoint is the API URL
- Headers must be used in list format
- Whitelist headers keeps the output clean, but only showing the headers listed
- `method` can be any HTTP method
- `endpoint` is the API URL
- `headers` must be used in list format
- `allow-headers` keeps the output clean, but only showing the headers listed

If you're just trying out Sendex, feel free to use a test API, such as [JSON Placeholder](https://jsonplaceholder.typicode.com). Replace the default endpoint with `https://jsonplaceholder.typicode.com/todos/{id}`.

Expand Down
16 changes: 8 additions & 8 deletions config/templates.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package config

var DefaultTemplate []byte = []byte("args:\n - id: 1 # specify 1 as default\nmethod: GET\nendpoint: http://localhost:8000/blog/{id} # we can use 'id' here\nheaders:\n - Content-Type: application/json\n - Accept: application/json\nwhitelist-headers:\n - Content-Type\n - Accept\n")
var PostTemplate []byte = []byte("args:\n - id: 1 # specify 1 as default\nmethod: POST\nendpoint: http://localhost:8000/blog/{id} # we can use 'id' here\nheaders:\n - Content-Type: application/json\n - Accept: application/json\nwhitelist-headers:\n - Content-Type\n - Accept\n")
var DefaultTemplate []byte = []byte("args:\n - id: 1 # specify 1 as default\nmethod: GET\nendpoint: http://localhost:8000/blog/{id} # we can use 'id' here\nheaders:\n - Content-Type: application/json\n - Accept: application/json\nallow-headers:\n - Content-Type\n")
var PostTemplate []byte = []byte("args:\n - id: 1 # specify 1 as default\nmethod: POST\nendpoint: http://localhost:8000/blog/{id} # we can use 'id' here\nheaders:\n - Content-Type: application/json\n - Accept: application/json\nallow-headers:\n - Content-Type\n")

type RequestSchema struct {
Args []map[string]string `yaml:"args"`
Method string `yaml:"method"`
Endpoint string `yaml:"endpoint"`
Headers []map[string]string `yaml:"headers"`
Body string `yaml:"body"`
WhitelistHeaders []string `yaml:"whitelist-headers"`
Args []map[string]string `yaml:"args"`
Method string `yaml:"method"`
Endpoint string `yaml:"endpoint"`
Headers []map[string]string `yaml:"headers"`
Body string `yaml:"body"`
AllowHeaders []string `yaml:"allow-headers"`
}
2 changes: 1 addition & 1 deletion examples/get-todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ endpoint: http://jsonplaceholder.typicode.com/todos/{id} # we can use 'id' here
headers:
- Content-Type: application/json
- Accept: application/json
whitelist-headers:
allow-headers:
- Content-Type
2 changes: 1 addition & 1 deletion examples/post-todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ body: |
headers:
- Content-Type: application/json
- Accept: application/json
whitelist-headers:
allow-headers:
- Nil
4 changes: 2 additions & 2 deletions internal/output/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ func (b *Buffer) Status(response *http.Response) {
}
}

func (b *Buffer) Head(response *http.Response, whitelistHeaders []string) error {
func (b *Buffer) Head(response *http.Response, AllowHeaders []string) error {
for header, value := range response.Header {
if len(whitelistHeaders) == 0 || slices.Contains(whitelistHeaders, header) {
if len(AllowHeaders) == 0 || slices.Contains(AllowHeaders, header) {
b.HeaderItem(header, value)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func GenerateOutput(response *http.Response, config *OutputConfig) (string, erro
}

if config.ShowHead {
err := buff.Head(response, config.Request.WhitelistHeaders)
err := buff.Head(response, config.Request.AllowHeaders)
if err != nil {
return "", err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/output/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestResponseWithOnlyHeaders(t *testing.T) {
}
}

func TestResponseWithWhitelistedHeaders(t *testing.T) {
func TestResponseWithAllowedHeaders(t *testing.T) {
expectedOutput := Cyan + "Content-Type" + Reset + ": application/json\n"

response := http.Response{
Expand All @@ -120,7 +120,7 @@ func TestResponseWithWhitelistedHeaders(t *testing.T) {
outputConfig.ShowBody = false
outputConfig.ShowStatus = false
outputConfig.Request = &config.RequestSchema{
WhitelistHeaders: []string{"Content-Type"},
AllowHeaders: []string{"Content-Type"},
}

output := captureStdout(func() {
Expand Down
2 changes: 1 addition & 1 deletion tests/404-todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ endpoint: http://jsonplaceholder.typicode.com/todos/sdf
headers:
- Content-Type: application/json
- Accept: application/json
whitelist-headers:
allow-headers:
- Content-Type
2 changes: 1 addition & 1 deletion tests/get-todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ endpoint: http://jsonplaceholder.typicode.com/todos/{id} # we can use 'id' here
headers:
- Content-Type: application/json
- Accept: application/json
whitelist-headers:
allow-headers:
- Content-Type
2 changes: 1 addition & 1 deletion tests/post-todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ endpoint: http://jsonplaceholder.typicode.com/todos # we can use 'id' here
headers:
- Content-Type: application/json
- Accept: application/json
whitelist-headers:
allow-headers:
- Content-Type
body: |
{
Expand Down