最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What does colon ':' in API request mean? - Stack Overflow

programmeradmin0浏览0评论

i am using firebase for my project ,the documentation gives me the endpoint for signing in users as:

:signInWithPassword?key=[API_KEY]

i want to know what does the colon : mean, for example the word key after the question mark shows its a parameter likewise what does the notion accounts:signInWithPassword mean.The reason:I have an axios instance with config:

axios.create(
  {
    baseURL:"",
    params:{
    apiKey:"somekey"
    }
  })

now since the baseUrl shown above remains same for firebase signing in with email and password or signing up with email and password. I want to dynamically embed accounts:signInWithPassword and accounts:signUp for respective requests and i am not sure if specifying accounts:respectiveUsecase in params object would work.

i am using firebase for my project ,the documentation gives me the endpoint for signing in users as:

https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=[API_KEY]

i want to know what does the colon : mean, for example the word key after the question mark shows its a parameter likewise what does the notion accounts:signInWithPassword mean.The reason:I have an axios instance with config:

axios.create(
  {
    baseURL:"https://identitytoolkit.googleapis.com/v1",
    params:{
    apiKey:"somekey"
    }
  })

now since the baseUrl shown above remains same for firebase signing in with email and password or signing up with email and password. I want to dynamically embed accounts:signInWithPassword and accounts:signUp for respective requests and i am not sure if specifying accounts:respectiveUsecase in params object would work.

Share Improve this question edited Mar 28, 2022 at 16:12 Arvind Maurya 92813 silver badges25 bronze badges asked Apr 27, 2020 at 7:25 Abdullah SohailAbdullah Sohail 4351 gold badge6 silver badges10 bronze badges 4
  • 1 That's a regular colon, not a semicolon – CertainPerformance Commented Apr 27, 2020 at 7:26
  • @CertainPerformance aand what does that mean ? – Abdullah Sohail Commented Apr 27, 2020 at 7:28
  • 3 Nothing per se. It's a naming convention specific to that API. – deceze Commented Apr 27, 2020 at 7:29
  • It's just part of the text. Nothing particularly significant to it - it could have been accounts-signInWithPassword or accounts_signInWithPassword and it'd work the same. – VLAZ Commented Apr 27, 2020 at 7:29
Add a comment  | 

3 Answers 3

Reset to default 8

A colon doesn't have any special meaning in an URL path. It's just a convention those APIs tend to use in their paths.

There are a handful of metacharacters that do:

  • question marks (?) and hashes (#) delimit the query or search parts
  • % is used for escaping characters (e.g. %0A)
  • + is sometimes an encoding for a space instead of %20.
  • & generally separates query parameters (e.g. foo=bar&baz), though this is not a part of the standard. Some server software could expect e.g. semicolon-separated parameters.

As @deceze pointed out, colons do have a special meaning in the host part, e.g. https://user:pass@host/path:where:colons:do:not:matter.

As others have said - a colon doesn't mean anything special in the URL.

However - I've just read "API Design Patterns" by JJ Geewax (ex-Google engineer who has worked on Firebase) - in it he describes colons being used to signify custom methods (so anything that doesn't fit in the standard POST/GET/PUT/DELETE methods that are seen in for many REST APIs), exactly as you have described with your signInWithPassword method. So it seems to be the Google way of doing things.

It is a dynamic value (like a parameter where you in pass in a value directly)

:nounId: The colon (:) before the word indicates that we don't mean the literal string "nounId" as part of the endpoint, but rather that we are expecting some dynamic data to be inside there. From the above example of /ski/:skiId, one actual endpoint might be something like /ski/1234 (where 1234 is the unique ID number of one of the skis in our database.

source: https://coursework.vschool.io/rest-api-design/#:~:text=%3AnounId%20%3A%20The%20colon%20(%3A)%20before,data%20to%20be%20inside%20there.

发布评论

评论列表(0)

  1. 暂无评论