Skip to content

Suggestions for Url-Api #433

Open
Open
@samuelpilz

Description

@samuelpilz

I did a review of the url-api. My motivation is that I did not understand how this module is intended to be used and saw an opportunity to improving discoverability and perceived consistency of the api.

I believe I understand the intention behind the provided functionality. I understand its usecases for routing and I do not want to remove any features from the module.

Name the new parts of the url

The Url struct is not the typical url. It represents more than just the url (it has extra features for routing). All parts of a typical url are already named corretly (path, hash, search). The "Base path" is a concept introduced by the routing-functionaliyt and is implicitly named.

I suggest embracing concept of the base-path. In current terms, it is the parts of the path that are "behind" of the url. The functions to_base_url and skip_base_path hint at that fact.
If there is a "base-path", there should also be a name for the rest. I see two possibilities:

  • path = base-path + head-path. The name head_path is the best name I could came up with, it is to be bikeshed.
  • absolute-path = base-path + path. This would be a breaking change and is quite disruptive.

The following describe suggested changes to functions:

to_base_url

This method clones the url and truncates the path. Suggestions:

  • The method should take &mut self to avoid cloning inside the library - users can still clone if they like to.
  • The method does not truncate the hash, which it should. Conceptually, the hash comes "after" the path.

next_path_part

Instead of "Advances the internal path iterator", the documentation of this method desccribe somthing along the lines of: "the next part of the url is moved to the base-url section of the path".

return string slices

  • implement base_path(&self) -> &[String].
  • remaining_path_parts should be head_path(&self) -> &[String] (no mut, return slice instead of vec)

documentation

consistent subtitle

URL used for routing can serve as a subtitle for seed's concept of url and could to be communicated more. This highlights that this is not the typical url-struct (just data) and serves the specific purpose. It should also documented that the url-path is split into

  • module-level description should start with that
  • struct-description should start with that (it already does)
  • guide-documentation

const DUMMY_BASE_URL

This is a const to "example.com". This seems a bit odd, currently the url-struct represents relative urls (which is nice). Having this const in the framework does not make much sense.

struct_urls macro seems off

It generates a newtype around a base-url. I understand that the custom methods (like home()) can be useful, but I doubt that this is the best abstraction.
I suggest removing the struct_urls! macro and having the users require to store the base-path inside the model. The functions like home() can still be implemented somewere.

reorder URL-methods

I had a difficult time understanding the nature of the url-module because the main mehtods for the entry-level user are quite hidden. Is there any possibility to reorder the methods?

  • getter (path, search, ...)
  • action methods go_*
  • setter
  • iter

Alternatively, one could extend the struct-level documentation to include examples about the most commonly used functions in simple apps (path, next, ...).

Metadata

Metadata

Assignees

No one assigned

    Labels

    API designProposal for a new or updated Seed API.enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions