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

feat: Support JSON payload in HTTP requests #213

Merged
merged 10 commits into from
Oct 27, 2023
Merged

Conversation

AsabuHere
Copy link
Contributor

Fixes

A short description of what this PR does.
Adding previewmessaging files to rc branch for json ingress

Checklist

  • I acknowledge that all my contributions will be made under the project's license
  • I have made a material change to the repo (functionality, testing, spelling, grammar)
  • I have read the Contribution Guidelines and my PR follows them
  • I have titled the PR appropriately
  • I have updated my branch with the main branch
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation about the functionality in the appropriate .md file
  • I have added inline documentation to the code I modified

If you have questions, please file a support ticket, or create a GitHub Issue in this repository.

@AsabuHere AsabuHere changed the title feat: Adding previewmessaging files to rc branch do not merge feat: Adding previewmessaging files to rc branch Oct 13, 2023
client/client.go Outdated Show resolved Hide resolved
client/client.go Outdated Show resolved Hide resolved
client/client.go Outdated Show resolved Hide resolved
client/client.go Outdated Show resolved Hide resolved
@AsabuHere AsabuHere changed the title do not merge feat: Adding previewmessaging files to rc branch feat: Adding previewmessaging files to rc branch Oct 19, 2023
@AsabuHere AsabuHere requested a review from sbansla October 19, 2023 06:27
@AsabuHere AsabuHere changed the title feat: Adding previewmessaging files to rc branch feat: Support JSON payload in HTTP requests Oct 19, 2023
} 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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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) {
Copy link
Contributor

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 ?

Copy link
Contributor Author

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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

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.

@AsabuHere
Copy link
Contributor Author

Added tickets for review comments : https://issues.corp.twilio.com/browse/DII-1210

@AsabuHere
Copy link
Contributor Author

Test cases will be added before merging to main branch

@AsabuHere AsabuHere merged commit b6200d6 into 2.0.0-rc Oct 27, 2023
10 of 11 checks passed
@AsabuHere AsabuHere deleted the go_json_ingress branch October 27, 2023 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants