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

Support serialization of url query parameters #182

Merged
merged 3 commits into from
Jul 27, 2022

Conversation

mahsashadi
Copy link
Contributor

No description provided.

Comment on lines 32 to 34
// /*
// * Creates URL request path
// */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove duplicate comment characters :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! sorry for that.

// */
export const encodeQueryData = (data) => {
const replacer = (k, v)=>(v === undefined ? null : v);
const pairs = Object.entries(data).map(([key, val]) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be better to just filter out any null-ish values before doing the encoding. The backend doesn't really take null or undefined values anyway.

This way you can just do the following:

const pairs = Object.entries(data)
  .filter(([, val]) => val !== null && val !== undefined)
  .map(([key, val]) => {
    const value = typeof val === 'object' ? JSON.stringify(val) : val;
    return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
  });

@mahsashadi
Copy link
Contributor Author

mahsashadi commented Jul 27, 2022

@andersevenrud changes are done.

As I said here, there were some issues about filtering client options passed. Do you want those to consider in this pull request?
#164 (review)
a5e92a1
14615e5

@andersevenrud
Copy link
Member

andersevenrud commented Jul 27, 2022

filtering client options passed

I'm not I sure I fully understand the issue.

Edit: Let's split out everything into single PRs. It's much easier to manage this way :)

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.

None yet

2 participants