Skip to content

Encoded version of path variables should be used #4

Open
@joshua-econify

Description

@joshua-econify

Module currently uses decoded path variables via req params:

asExpressRoute() {
    return async (req: express.Request, res: express.Response) => {
      const { query, params, body } = req;
      
      const parsedQueryVariables = this.typecastVariables(query);
      const parsedPathVariables = this.typecastVariables(params);
...

https://github.com/Econify/graphql-rest-router/blob/master/Route.ts#L290

req.params implicitly decodes each part of the path into a corresponding path variable.

If one of the path variables is used as a slug, then that slug would need to be stored decoded in the database in order to be looked up. Storing a slug as a decoded path means the slug is no longer a valid part of a URL. If the slug is used for embedded URLs this means it will have to be encoded every time.

Since a slug is part of URL, believe it is a reasonable expectation of consumers of the library to store slugs in a valid encoded form.

To my knowledge, because const { params } = req; implicitly decodes each value in the object, it is currently impossible to look up an encoded slug.

Thoughts/ideas/gotchas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions