Skip to content

Support serialization of url query parameters#182

Merged
andersevenrud merged 3 commits into
os-js:masterfrom
mahsashadi:feature/url-serialization
Jul 27, 2022
Merged

Support serialization of url query parameters#182
andersevenrud merged 3 commits into
os-js:masterfrom
mahsashadi:feature/url-serialization

Conversation

@mahsashadi
Copy link
Copy Markdown
Contributor

No description provided.

Comment thread src/utils/fetch.js Outdated
Comment on lines +32 to +34
// /*
// * Creates URL request path
// */
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread src/utils/fetch.js Outdated
// */
export const encodeQueryData = (data) => {
const replacer = (k, v)=>(v === undefined ? null : v);
const pairs = Object.entries(data).map(([key, val]) => {
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

2 participants