-
Notifications
You must be signed in to change notification settings - Fork 41
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
feat: Support JSON payload in HTTP requests #213
Conversation
} else { | ||
//Here the HTTP POST methods which is not having json content type are processed | ||
//All the values will be added in data and encoded (all body, query, path parameters) | ||
if method == http.MethodPost { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Going forward PUT method can be used for update operation which will have request body.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should i add support for that as well now?
@@ -23,13 +23,12 @@ func NewRequestHandler(client BaseClient) *RequestHandler { | |||
} | |||
|
|||
func (c *RequestHandler) sendRequest(method string, rawURL string, data url.Values, | |||
headers map[string]interface{}) (*http.Response, error) { | |||
headers map[string]interface{}, body ...byte) (*http.Response, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case of json body will data be null ? If yes, then try to check if method overload possible in go ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method overloading is not possible in go, in case of json body data need to be null, it can contain query parameters
@@ -83,8 +82,8 @@ func (c *RequestHandler) BuildUrl(rawURL string) (string, error) { | |||
return u.String(), nil | |||
} | |||
|
|||
func (c *RequestHandler) Post(path string, bodyData url.Values, headers map[string]interface{}) (*http.Response, error) { | |||
return c.sendRequest(http.MethodPost, path, bodyData, headers) | |||
func (c *RequestHandler) Post(path string, bodyData url.Values, headers map[string]interface{}, body ...byte) (*http.Response, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might need to change method name as PUT operation will be allowed after some time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we change name now?
// are added as information in the url itself. Also while Content-Type is json, we are sending | ||
// json body. In that case, data variable conatins all other parameters than body, which is the | ||
//same case as GET method. In that case as well all parameters will be added to url | ||
if method == http.MethodGet || contentType == jsonContentType{ | ||
if data != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously only GET method was supposed to have query parameter, going forward any method can have query parameter.
Added tickets for review comments : https://issues.corp.twilio.com/browse/DII-1210 |
Test cases will be added before merging to main branch |
Fixes
A short description of what this PR does.
Adding previewmessaging files to rc branch for json ingress
Checklist
If you have questions, please file a support ticket, or create a GitHub Issue in this repository.