pub struct Client { /* private fields */ }Expand description
An async client for the UK Police API.
§Example
let client = uk_police_api::Client::new();
let forces = client.forces().await?;Implementations§
Source§impl Client
impl Client
pub fn new() -> Self
Sourcepub fn from_http_client(http: Client) -> Self
pub fn from_http_client(http: Client) -> Self
Creates a client with a pre-configured reqwest::Client.
Use this to customize timeouts, headers, proxies, or any other HTTP behaviour.
§Example
let http = reqwest::Client::builder()
.timeout(std::time::Duration::from_secs(10))
.build()
.unwrap();
let client = uk_police_api::Client::from_http_client(http);Sourcepub async fn force(&self, id: &str) -> Result<ForceDetail, Error>
pub async fn force(&self, id: &str) -> Result<ForceDetail, Error>
Returns details for a specific police force.
Sourcepub async fn crime_categories(
&self,
date: Option<&str>,
) -> Result<Vec<CrimeCategory>, Error>
pub async fn crime_categories( &self, date: Option<&str>, ) -> Result<Vec<CrimeCategory>, Error>
Returns a list of crime categories. Optionally filtered by date (format: YYYY-MM).
Sourcepub async fn street_level_crimes(
&self,
category: &str,
area: &Area,
date: Option<&str>,
) -> Result<Vec<Crime>, Error>
pub async fn street_level_crimes( &self, category: &str, area: &Area, date: Option<&str>, ) -> Result<Vec<Crime>, Error>
Returns street-level crimes within a given area.
§Arguments
category- Crime category slug (e.g. “all-crime”, “burglary”). SeeClient::crime_categories.area- Either a point (1 mile radius) or a custom polygon.date- Optional month filter (format:YYYY-MM). Defaults to the latest available.
Sourcepub async fn street_level_outcomes(
&self,
area: &Area,
date: Option<&str>,
) -> Result<Vec<Outcome>, Error>
pub async fn street_level_outcomes( &self, area: &Area, date: Option<&str>, ) -> Result<Vec<Outcome>, Error>
Returns street-level outcomes at a given location.
§Arguments
area- A point (1 mile radius), custom polygon, or specific location ID.date- Optional month filter (format:YYYY-MM). Defaults to the latest available.
Sourcepub async fn crime_last_updated(&self) -> Result<CrimeLastUpdated, Error>
pub async fn crime_last_updated(&self) -> Result<CrimeLastUpdated, Error>
Returns the date when crime data was last updated.
Sourcepub async fn senior_officers(
&self,
force_id: &str,
) -> Result<Vec<SeniorOfficer>, Error>
pub async fn senior_officers( &self, force_id: &str, ) -> Result<Vec<SeniorOfficer>, Error>
Returns a list of senior officers for a given force.
Sourcepub async fn crimes_at_location(
&self,
location_id: u64,
date: Option<&str>,
) -> Result<Vec<Crime>, Error>
pub async fn crimes_at_location( &self, location_id: u64, date: Option<&str>, ) -> Result<Vec<Crime>, Error>
Returns crimes at a specific location.
§Arguments
location_id- A location ID (from a street’sidfield).date- Optional month filter (format:YYYY-MM). Defaults to the latest available.
Sourcepub async fn crimes_no_location(
&self,
category: &str,
force: &str,
date: Option<&str>,
) -> Result<Vec<Crime>, Error>
pub async fn crimes_no_location( &self, category: &str, force: &str, date: Option<&str>, ) -> Result<Vec<Crime>, Error>
Returns crimes that could not be mapped to a location.
§Arguments
category- Crime category slug (e.g. “all-crime”). SeeClient::crime_categories.force- Force identifier (e.g. “metropolitan”).date- Optional month filter (format:YYYY-MM). Defaults to the latest available.
Sourcepub async fn outcomes_for_crime(
&self,
persistent_id: &str,
) -> Result<CrimeOutcomes, Error>
pub async fn outcomes_for_crime( &self, persistent_id: &str, ) -> Result<CrimeOutcomes, Error>
Returns all outcomes for a specific crime.
§Arguments
persistent_id- The 64-character crime identifier.
Sourcepub async fn neighbourhoods(
&self,
force_id: &str,
) -> Result<Vec<Neighbourhood>, Error>
pub async fn neighbourhoods( &self, force_id: &str, ) -> Result<Vec<Neighbourhood>, Error>
Returns a list of neighbourhoods for a force.
Sourcepub async fn neighbourhood(
&self,
force_id: &str,
neighbourhood_id: &str,
) -> Result<NeighbourhoodDetail, Error>
pub async fn neighbourhood( &self, force_id: &str, neighbourhood_id: &str, ) -> Result<NeighbourhoodDetail, Error>
Returns details for a specific neighbourhood.
Sourcepub async fn neighbourhood_boundary(
&self,
force_id: &str,
neighbourhood_id: &str,
) -> Result<Vec<LatLng>, Error>
pub async fn neighbourhood_boundary( &self, force_id: &str, neighbourhood_id: &str, ) -> Result<Vec<LatLng>, Error>
Returns the boundary of a neighbourhood as a list of lat/lng pairs.
Sourcepub async fn neighbourhood_team(
&self,
force_id: &str,
neighbourhood_id: &str,
) -> Result<Vec<SeniorOfficer>, Error>
pub async fn neighbourhood_team( &self, force_id: &str, neighbourhood_id: &str, ) -> Result<Vec<SeniorOfficer>, Error>
Returns the policing team for a neighbourhood.
Sourcepub async fn neighbourhood_events(
&self,
force_id: &str,
neighbourhood_id: &str,
) -> Result<Vec<NeighbourhoodEvent>, Error>
pub async fn neighbourhood_events( &self, force_id: &str, neighbourhood_id: &str, ) -> Result<Vec<NeighbourhoodEvent>, Error>
Returns events for a neighbourhood.
Sourcepub async fn neighbourhood_priorities(
&self,
force_id: &str,
neighbourhood_id: &str,
) -> Result<Vec<NeighbourhoodPriority>, Error>
pub async fn neighbourhood_priorities( &self, force_id: &str, neighbourhood_id: &str, ) -> Result<Vec<NeighbourhoodPriority>, Error>
Returns policing priorities for a neighbourhood.
Sourcepub async fn locate_neighbourhood(
&self,
lat: f64,
lng: f64,
) -> Result<LocateNeighbourhoodResult, Error>
pub async fn locate_neighbourhood( &self, lat: f64, lng: f64, ) -> Result<LocateNeighbourhoodResult, Error>
Locates the neighbourhood policing team responsible for a given point.
Sourcepub async fn stops_street(
&self,
area: &Area,
date: Option<&str>,
) -> Result<Vec<StopAndSearch>, Error>
pub async fn stops_street( &self, area: &Area, date: Option<&str>, ) -> Result<Vec<StopAndSearch>, Error>
Returns stop and searches within a given area.
§Arguments
area- A point (1 mile radius) or custom polygon.date- Optional month filter (format:YYYY-MM). Defaults to the latest available.
Sourcepub async fn stops_at_location(
&self,
location_id: u64,
date: Option<&str>,
) -> Result<Vec<StopAndSearch>, Error>
pub async fn stops_at_location( &self, location_id: u64, date: Option<&str>, ) -> Result<Vec<StopAndSearch>, Error>
Returns stop and searches at a specific location.
§Arguments
location_id- A location ID (from a street’sidfield).date- Optional month filter (format:YYYY-MM). Defaults to the latest available.
Sourcepub async fn stops_no_location(
&self,
force: &str,
date: Option<&str>,
) -> Result<Vec<StopAndSearch>, Error>
pub async fn stops_no_location( &self, force: &str, date: Option<&str>, ) -> Result<Vec<StopAndSearch>, Error>
Returns stop and searches that could not be mapped to a location.
§Arguments
force- Force identifier (e.g. “metropolitan”).date- Optional month filter (format:YYYY-MM). Defaults to the latest available.
Sourcepub async fn stops_force(
&self,
force: &str,
date: Option<&str>,
) -> Result<Vec<StopAndSearch>, Error>
pub async fn stops_force( &self, force: &str, date: Option<&str>, ) -> Result<Vec<StopAndSearch>, Error>
Returns stop and searches reported by a force.
§Arguments
force- Force identifier (e.g. “metropolitan”).date- Optional month filter (format:YYYY-MM). Defaults to the latest available.