简体   繁体   中英

How to hit the rest endpoint that has `:.*` as a part of the path param field

I am using the Stash's REST API in my project. My task is to get the tag details for a specific tag. After checking the Stash's REST API documentation, I found the correct endpoint that I should be using. It is

/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/tags/{name:.*}

Please see this link for the Stash's REST API documentation.

There is one more endpoint /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/tags
With this endpoint I am able to retrieve all the tags. The StashTag object looks something like this.

  {
    "id": "refs/tags/v4.0.0",
    "displayId": "v4.0.0",
    "latestChangeset": "234dadf41742cfc2a10cadc7c2364438bd8891c5",
    "latestCommit": "234dadf41742cfc2a10cadc7c2278658bd8891c5"
    "hash" : "null"
  }

My first problem is, I don't know which field to use as the parameter for {name:.*} . Should it be the displayId or Id or anything else.

The second problem is, I don't understand what it means to have : (colon) followed by a . (dot) in the endpoint /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/tags/{name:.*} .

Can someone explain me what is the purpose of :. in the path param and how to hit this kind of an endpoint. Also an example of the complete endpoint would be nice.

So far I have tried hitting

https://stashtest.abc.com/rest/api/1.0/projects/KARTIK/repos/kartiks-test-repository/tags/v4.0.0
https://stashtest.abc.com/rest/api/1.0/projects/KARTIK/repos/kartiks-test-repository/tags/refs/tags/v4.0.0  

None of these endpoints work.

Any help is appreciated.

The {name:.*} is really just saying that the field name can be anything. Chalk this one up to poor documentation on their part. Think of it like Regex field, because that's exactly what it is. I'm sure at one point they had something like ^[0-9] then went back and changed it when they realized using only tag numbers would omit anyone using their lightweight tag features.

Remove the v from your tag version and see if that helps. If it does not, I would also recommend creating a lightweight tag (something like mytag ) and seeing if you can hit it that way (ie, /kartiks-test-repository/tags/mytag ).

But looking at that documentation is telling me that your v in your tag name is throwing off the REST call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM