Skip to content

Question: String Literals vs net/http Constants #3695

@jferrl

Description

@jferrl

Hi @gmlewis ! 👋

I've been exploring the codebase and noticed a pattern in how HTTP methods are handled throughout the library. I'm curious about the design decision and would love to understand the reasoning better.

What I Observed

The library currently uses a mixed approach for HTTP methods:

  • String literals: Many files use "GET", "POST", "PUT", "DELETE", "PATCH" directly
  • net/http constants: Some files use http.MethodGet, http.MethodPost, etc.

Examples:

// String literals (found in many files)
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("POST", u, opts)

// net/http constants (found in some files)
req, err := s.client.NewRequest(http.MethodGet, u, nil)
req, err := http.NewRequest(http.MethodPost, u.String(), body)

My Questions

  1. Are there specific reasons for preferring string literals in some cases and constants in others?

  2. Would you be open to contributions that standardize this usage? (I'm not suggesting changes yet, just curious about the maintainers' thoughts)

Note

I'm not proposing any changes at this point - I'm just trying to understand the design philosophy and whether this is something the maintainers would like to see addressed in the future.

Thanks!

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