Changeset View
Changeset View
Standalone View
Standalone View
swh/web/api/views/origin.py
Show First 20 Lines • Show All 188 Lines • ▼ Show 20 Lines | .. http:get:: /api/1/origin/search/(url_pattern)/ | ||||
.. warning:: | .. warning:: | ||||
This endpoint used to provide an `offset` query parameter, | This endpoint used to provide an `offset` query parameter, | ||||
and guarantee an order on results. This is no longer true, | and guarantee an order on results. This is no longer true, | ||||
and only the Link header should be used for paginating through | and only the Link header should be used for paginating through | ||||
results. | results. | ||||
:param string url_pattern: a string pattern or a regular expression | :param string url_pattern: a string pattern | ||||
:query int limit: the maximum number of found origins to return | :query int limit: the maximum number of found origins to return | ||||
(bounded to 1000) | (bounded to 1000) | ||||
:query boolean regexp: if true, consider provided pattern as a regular | |||||
expression and search origins whose urls match it | |||||
:query boolean with_visit: if true, only return origins with at least | :query boolean with_visit: if true, only return origins with at least | ||||
one visit by Software heritage | one visit by Software heritage | ||||
{return_origin_array} | {return_origin_array} | ||||
{common_headers} | {common_headers} | ||||
{resheader_link} | {resheader_link} | ||||
**Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, | **Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, | ||||
:http:method:`options` | :http:method:`options` | ||||
:statuscode 200: no error | :statuscode 200: no error | ||||
**Example:** | **Example:** | ||||
.. parsed-literal:: | .. parsed-literal:: | ||||
:swh_web_api:`origin/search/python/?limit=2` | :swh_web_api:`origin/search/python/?limit=2` | ||||
""" | """ | ||||
result = {} | result = {} | ||||
offset = int(request.query_params.get('offset', '0')) | offset = int(request.query_params.get('offset', '0')) | ||||
limit = min(int(request.query_params.get('limit', '70')), 1000) | limit = min(int(request.query_params.get('limit', '70')), 1000) | ||||
regexp = request.query_params.get('regexp', 'false') | |||||
with_visit = request.query_params.get('with_visit', 'false') | with_visit = request.query_params.get('with_visit', 'false') | ||||
results = api_lookup(service.search_origin, url_pattern, offset, limit, | results = api_lookup(service.search_origin, url_pattern, offset, limit, | ||||
bool(strtobool(regexp)), bool(strtobool(with_visit)), | bool(strtobool(with_visit)), | ||||
enrich_fn=_enrich_origin) | enrich_fn=_enrich_origin) | ||||
nb_results = len(results) | nb_results = len(results) | ||||
if nb_results == limit: | if nb_results == limit: | ||||
query_params = {} | query_params = {} | ||||
query_params['offset'] = offset + limit | query_params['offset'] = offset + limit | ||||
query_params['limit'] = limit | query_params['limit'] = limit | ||||
query_params['regexp'] = regexp | |||||
result['headers'] = { | result['headers'] = { | ||||
'link-next': reverse('api-1-origin-search', | 'link-next': reverse('api-1-origin-search', | ||||
url_args={'url_pattern': url_pattern}, | url_args={'url_pattern': url_pattern}, | ||||
query_params=query_params) | query_params=query_params) | ||||
} | } | ||||
result.update({ | result.update({ | ||||
▲ Show 20 Lines • Show All 262 Lines • Show Last 20 Lines |