Skip to content
This repository has been archived by the owner on Jul 14, 2022. It is now read-only.

Commit

Permalink
[Refactor] Better SEND method
Browse files Browse the repository at this point in the history
Refactored a Lot. Moved functions to methods. Rather than returning strings, now send method directly prints to stdout synchrounously. Support for Full Body POST and PUT requests. Folder Support.
  • Loading branch information
athul committed Oct 14, 2020
1 parent bdfe632 commit 4ae116b
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 144 deletions.
12 changes: 9 additions & 3 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,15 @@ func main() {
Name: "send",
Usage: "Test all the Endpoints in the Hoppscotch Collection.json",
Action: func(c *cli.Context) error {
var err error
out, err = mets.ReadCollection(c)
return err
coll, err := mets.ReadCollection(c.Args().Get(0))
if err != nil {
return err
}
_, err = mets.ProcessCollection(coll)
if err != nil {
return err
}
return nil
},
},
}
Expand Down
72 changes: 72 additions & 0 deletions methods/collection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package methods

//Collection hold the structure of the basic `postwoman-collection.json`
type Collection struct {
// Name of the Whole Collection
Name string `json:"name"`
// Folders JSON Type
Folders []Folders `json:"folders"`
// Requests inside the Collection
Requests []Requests `json:"requests"`
}

// Folders can be organized to Folders
type Folders struct {
// Folder name
Name string `json:"name"`
// Requests inside the Folder
Requests []Requests `json:"requests"`
}

// Headers are the Request Headers
type Headers struct {
Key string `json:"key"`
Value string `json:"value"`
}

// Requests are the Request Model in JSON
type Requests struct {
// Base URL of the Request
URL string `json:"url"`
// Path is the enpoint path
// URL+PATH = Full URL
Path string `json:"path"`
// Request Method - GET,POST,PUT,PATCH,DELETE
Method string `json:"method"`
// Authentication Type - Bearer Token or Basic Auth
Auth string `json:"auth"`
// Username for Basic Auth
User string `json:"httpUser"`
// Password for Basic Auth
Pass string `json:"httpPassword"`
PasswordFieldType string `json:"passwordFieldType"`
// Bearer token
Token string `json:"bearerToken"`
// Request Headers if any- Key,Value pairs
Headers []Headers `json:"headers"`
// Params for Get Requests
Params []interface{} `json:"params"`
// Body Params for POST requests and forth
Bparams []interface{} `json:"bodyParams"`
// Raw Input. Not Formatted JSON
RawParams string `json:"rawParams"`
// If RawInputs are used or Not
RawInput bool `json:"rawInput"`
// Content Type of Request
Ctype string `json:"contentType"`
RequestType string `json:"requestType"`
PreRequestScript string `json:"preRequestScript"`
TestScript string `json:"testScript"`
// Label of Collection
Label string `json:"label"`
// Name of the Request
Name string `json:"name"`
// Number of Collection
Collection int `json:"collection"`
}

// BodyParams include the Body Parameters
type BodyParams struct {
Key string `json:"key"`
Value string `json:"value"`
}
2 changes: 1 addition & 1 deletion methods/fns.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func basicAuth(username, password string) string {
return base64.StdEncoding.EncodeToString([]byte(auth))
}

//Contenttypes can be used in Place for ctypes
//Contenttypes are used in Place for ctypes for sending requests
var Contenttypes = map[string]string{
"html": "text/html",
"js": "application/json",
Expand Down

0 comments on commit 4ae116b

Please sign in to comment.