Coder Social home page Coder Social logo

Comments (2)

razor-x avatar razor-x commented on May 29, 2024

We need to support a the "common" array serialization formats.

Current support as of this comment

export type QueryArrayFormat = "brackets" | "comma" | "repeat"

Defaults must be updated when adding a new one:

export const DEFAULT_ARRAY_FORMATS: QueryArrayFormats = [

I think the main one we are missing is indexed which is like brackets but includes the index like ?foo[0]=a&foo[1]=b. This is the default used by axios (and possibly Ruby's HTTP gem and others).

Note that the "standard" format is generally agreed to be repeat since this is what URLSearchParams does (and does not mangle the name or value in the query string), but all formats are "non-standard".

All formats have drawbacks, but client libs are recommended to implement repeat. Critically, repeat has an ambiguity since a single element array containing the empty string foo= could be interpreted as either foo=[''] or foo=[]. This library will interpret this as [] which is often the intended behavior and more useful than ['']. Client libraries should disallow passing [''] to array params to prevent silently changing the intention of the caller.

A reference implementation for a compatible serializer may be found at https://github.com/seamapi/javascript-http/blob/main/src/lib/params-serializer.ts

from nextlove.

razor-x avatar razor-x commented on May 29, 2024

This library will interpret this as []

There may be a bug where this lib is actually parsing foo= as [undefined] or ['']. We need some tests around these edge cases. It should parse foo= as [].

from nextlove.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.