
Contents
Putting them to good use greatly depends on how you choose to harness and present the data. While a host of programming languages can be deployed to do so, in this developers’ guide, we shall explore match commentaries from Sportmonks’ Football API using RUST.
Each chapter will build on the next one as we go through each exercise. Now, let’s dive in!
What is Rust?
Rust is a general-purpose programming language emphasising performance, type safety, and concurrency. It’s known for its reliability and safety.
Software developer Graydon Hoare created Rust as a personal project while working at Mozilla Research in 2006, a project which the company officially sponsored three years later.
The programming language has been used in the development of software such as command line tools, web services, DevOps tooling, and search engines. It has also been used in programs for Internet of Things applications and machine learning.
Who Uses Rust?
Many years later, following the first stable release in May 2015, the programming language was adopted by several companies such as Amazon, Discord, and Dropbox. Firefox and Cloudflare are also applications built with Rust.
We shall put Rust to use in our blog to retrieve and format JSON data for match commentaries on any fixture of interest. Let’s sink our teeth into the task at hand.
WHY DO MATCH COMMENTARIES MATTER?
Match commentaries add a textual representation of the actions that take place during the course of a live match. As an alternative to live TV or streaming, they offer a clear picture of the game’s proceedings minute by minute.
While match previews and post-match reviews, which are also part of our robust Football API, offer the buildup and summary to the match, respectively, match commentaries offer a unique angle to the game’s coverage as it is live.
Why deny your users the opportunity to experience the game like never before with real-time, dynamic commentaries?
As we are about to show you, with a few lines of code and minimal programming skills, you too can integrate our Football API to give your users the thrill of live play-by-play updates. Sign up for a free trial now to begin!
CHAPTER 1. Setting up your environment
In order to write and compile Rust, we need to set up an environment to do so.
While there are a host of development tools available for use, we will choose the option of installing an IDE to get us up and running in no time.
1.1 Installing an IDE for Rust.
The platform-independent RustRover is an ideal choice for today’s exercise. Developed by JetBrains, the software is available for non-commercial use. Head over to the official website to install a suitable version on your workstation.
You may refer to the official installation guide for your use case.
You may be required to sign in for use of the non-commercial version. After installation, assuming all went according to plan, fire up the application.
However, before we continue, we shall need an API token for authentication.
1.2 Obtaining an API Token.
To use the API, sign up for an account if you haven’t already done so. Your account automatically comes with the Danish Super Liga and Scottish Premier League plans at no cost.
Head over to the ‘Create an API Token‘ section on the dashboard.
Once you have your API token, you must keep it private. Don’t hesitate to delete and create a new API token should it become compromised.
Chapter 2 Making Your First API Call.
As discussed earlier, we shall show you how to retrieve match commentaries from our Football API. Match commentaries are just a tip of the iceberg regarding our endpoints, which you can read all about on the official documentation page.
We shall begin our exercise by retrieving Match commentaries for all fixtures.
Chapter 2.1 Retrieving Available Commentaries.
Using our base URL, along with its API Token we can retrieve all available commentaries by placing the complete URL on a browser.
https://api.sportmonks.com/v3/football/commentaries?api_token=API_Token
We shall do the same using RUST.
use reqwest::Error; use serde_json::Value; #[tokio::main] async fn main() -> Result<(), Error> { // Replace "API_Token" with your actual API token let api_token = "API_Token"; let url = format!("https://api.sportmonks.com/v3/football/commentaries?api_token={}", api_token); // Send the GET request let response = reqwest::get(&url).await?; // Check if the request was successful if response.status().is_success() { // Parse the JSON response let json: Value = response.json().await?; // Print the JSON response println!("{:?}", json); } else { // Print an error message if the request failed eprintln!("Failed to fetch data: {}", response.status()); } Ok(()) }
Object {"data": Array [Object {"comment": String("First Half starts."), "extra_minute": Null, "fixture_id": Number(18444499), "id": Number(1), "is_goal": Bool(false), "is_important": Bool(false), "minute": Null, "order": Number(1)}, Object {"comment": String("Corner - Brisbane Roar FC. Conceded by Nicholas Pennington."), "extra_minute": Null, "fixture_id": Number(18444499), "id": Number(2), "is_goal": Bool(false), "is_important": Bool(false), "minute": Number(2), "order": Number(2)}, Object {"comment": String("Shot blocked. Ryo Wada - Brisbane Roar FC - shot with left foot from outside the box is blocked."), "extra_minute": Null, "fixture_id": Number(18444499), "id": Number(3), "is_goal": Bool(false), "is_important": Bool(false), "minute": Number(7), "order": Number(3)}, Object {"comment": String("Corner - Brisbane Roar FC. Conceded by Finn Surman."), "extra_minute": Null, "fixture_id": Number(18444499), "id": Number(5), "is_goal": Bool(false), "is_important": Bool(false), "minute": Number(8), "order": Number(5)}, Object {"comment": String("Shot blocked. David Ball - Wellington Phoenix - shot with left foot from the centre of the box is blocked."), "extra_minute": Null, "fixture_id": Number(18444499), "id": Number(8), "is_goal": Bool(false), "is_important": Bool(false), "minute": Number(13), "order": Numb er(8)}, Object {"comment": String("Fouled by James McGarry - Wellington Phoenix"), "extra_minute": Null, "fixture_id": Number(18444499), "id": Numb er(9), "is_goal": Bool(false), "is_important": Bool(false), "minute": Number(13), "order": Number(9)}, Object {"comment": String("Ryo Wada - Brisba ne Roar FC - won a free kick in defence."), "extra_minute": Null, "fixture_id": Number(18444499), "id": Number(10), "is_goal": Bool(false), "is_imp ortant": Bool(false), "minute": Number(13), "order": Number(10)}, Object {"comment": String("Missed chance. Luke Ivanovic - Brisbane Roar FC - sho t with right foot from outside the box is high and wide to the right. Assist - Anton Mlinaric."), "extra_minute": Null, "fixture_id": Number(184444 99), "id": Number(11), "is_goal": Bool(false), "is_important": Bool(false), "minute": Number(14), "order": Number(11)}, Object {"comment": String("L uke Ivanovic - Brisbane Roar FC - receive yellow card for a foul."), "extra_minute": Null, "fixture_id": Number(18444499), "id": Number(14), "is_g oal": Bool(false), "is_important": Bool(true), "minute": Number(17), "order": Number(14)}, Object {"comment": String("Missed chance. Juan Eduardo Le scano - Brisbane Roar FC - shot with right foot from the centre of the box."), "extra_minute": Null, "fixture_id": Number(18444499), "id": Number( 15), "is_goal": Bool(false), "is_important": Bool(false), "minute": Number(20), "order": Number(15)}, Object {"comment": String("New attacking attem pt. David Ball - Wellington Phoenix - shot with right foot from the left side of the box is saved."), "extra_minute": Null, "fixture_id": Number(1 8444499), "id": Number(16), "is_goal": Bool(false), "is_important": Bool(false), "minute": Number(21), "order": Number(16)}, Object {"comment": Stri ng("Fouled by Luke Ivanovic - Brisbane Roar FC"), "extra_minute": Null, "fixture_id": Number(18444499), "id": Number(17), "is_goal": Bool(false), " is_important": Bool(false), "minute": Number(22), "order": Number(17)}, Object {"comment": String("Louis Fenton - Wellington Phoenix - won a free kick in defence."), "extra_minute": Null, "fixture_id": Number(18444499), "id": Number(18), "is_goal": Bool(false), "is_important": Bool(false), "mi nute": Number(22), "order": Number(18)}, Object {"comment": String("Shot blocked. Nicholas Olsen - Brisbane Roar FC - shot with right foot from th e left side of the box is blocked."), "extra_minute": Null, "fixture_id": Number(18444499), "id": Number(19), "is_goal": Bool(false), "is_important" : Bool(false), "minute": Number(25), "order": Number(19)}, Object {"comment": String("New attacking attempt. Ryo Wada - Brisbane Roar FC - shot wi th left foot from the centre of the box is saved in the right corner. Assist - Nicholas Olsen with a cross."), "extra_minute": Null, "fixture_id": Number(18444499), "id": Number(20), "is_goal": Bool(false), "is_important": Bool(false), "minute": Number(25), "order": Number(20)}, Object {"commen t": String("Corner - Wellington Phoenix. Conceded by Scott Neville."), "extra_minute": Null, "fixture_id": Number(18444499), "id": Number(21), "is_ goal": Bool(false), "is_important": Bool(false), "minute": Number(27), "order": Number(21)}, Object {"comment": String("Missed chance. Ben Waine - Wellington Phoenix - with an attempt from few metres after corner."), "extra_minute": Null, "fixture_id": Number(18444499), "id": Number(22), "is_g oal": Bool(false), "is_important": Bool(false), "minute": Number(28), "order": Number(22)}, Object {"comment": String("Own Goal by Scott Neville, Br isbane Roar FC. Brisbane Roar FC 0, Wellington Phoenix 1."), "extra_minute": Null, "fixture_id": Number(18444499), "id": Number(23), "is_goal": Boo l(true), "is_important": Bool(true), "minute": Number(28), "order": Number(23)}, Object {"comment": String("Matti Steinmann - Brisbane Roar FC - w on a free kick in attack."), "extra_minute": Null, "fixture_id": Number(18444499), "id": Number(25), "is_goal": Bool(false), "is_important": Bool(fa lse), "minute": Number(33), "order": Number(25)}, Object {"comment": String("Missed chance. Kai Trewin - Brisbane Roar FC - shot with the head fro m the centre of the box goes high. Assist - Nicholas Olsen with a head."), "extra_minute": Null, "fixture_id": Number(18444499), "id": Number(26), "is_goal": Bool(false), "is_important": Bool(false), "minute": Number(34), "order": Number(26)}, Object {"comment": String("Fouled by Gael Sandoval - Wellington Phoenix"), "extra_minute": Null, "fixture_id": Number(18444499), "id": Number(27), "is_goal": Bool(false), "is_important": Bool(false) , "minute": Number(36), "order": Number(27)}, Object {"comment": String("Luke Ivanovic - Brisbane Roar FC - won a free kick on the left wing."), " extra_minute": Null, "fixture_id": Number(18444499), "id": Number(28), "is_goal": Bool(false), "is_important": Bool(false), "minute": Number(36), "o rder": Number(28)}, Object {"comment": String("Missed chance. Juan Eduardo Lescano - Brisbane Roar FC - header inside of six yard box - left side. "), "extra_minute": Null, "fixture_id": Number(18444499), "id": Number(29), "is_goal": Bool(false), "is_important": Bool(false), "minute": Number(37 ), "order": Number(29)}, Object {"comment": String("Corner - Brisbane Roar FC. Conceded by James McGarry."), "extra_minute": Null, "fixture_id": Nu mber(18444499), "id": Number(31), "is_goal": Bool(false), "is_important": Bool(false), "minute": Number(37), "order": Number(31)}, Object {"comment" : String("Corner - Brisbane Roar FC. Conceded by Benjamin Old."), "extra_minute": Null, "fixture_id": Number(18444499), "id": Number(32), "is_goal" : Bool(false), "is_important": Bool(false), "minute": Number(38), "order": Number(32)}], "pagination": Object {"count": Number(25), "current_page": Number(1), "has_more": Bool(true), "next_page": String("https://api.sportmonks.com/v3/football/commentaries?page=2"), "per_page": Number(25)}, "rate _limit": Object {"remaining": Number(2999), "requested_entity": String("Commentary"), "resets_in_seconds": Number(3600)}, "subscription": Array [Obj ect {"add_ons": Array [Object {"add_on": String("All-in News API"), "category": String("News"), "sport": String("Football")}, Object {"add_on": Stri ng("pressure index add-on"), "category": String("Default"), "sport": String("Football")}, Object {"add_on": String("Enterprise Plan Predictions"), " category": String("Predictions"), "sport": String("Football")}, Object {"add_on": String("xG Advanced"), "category": String("Expected"), "sport": St ring("Football")}], "meta": Object {"current_timestamp": Number(1735920769), "ends_at": Null, "trial_ends_at": String("2024-10-16 14:50:45")}, "plan s": Array [Object {"category": String("Advanced"), "plan": String("Enterprise plan (loyal)"), "sport": String("Football")}, Object {"category": Stri ng("Standard"), "plan": String("Enterprise Plan"), "sport": String("Cricket")}, Object {"category": String("Standard"), "plan": String("Formula One" ), "sport": String("Formula One")}], "widgets": Array [Object {"sport": String("Football"), "widget": String("Sportmonks Widgets")}]}], "timezone": String("UTC")}
Explanation.
Reqwest is a Rust crate for making HTTP requests, while the statement Error: handles errors that might occur during the HTTP request process.
The next line, serde_json::Value: Represents a JSON value. It’s flexible for handling unknown or dynamic JSON structures.
#[tokio::main]: Marks the main function as asynchronous, allowing you to use await for asynchronous tasks while async fn main() is the entry point of the program.
The format! statement constructs the URL string dynamically by inserting the API token into the URL. We also checked the response to ensure we received 200 OK. If not, we can crosscheck the received error response code with our documentation.
However, as you can see, the response is broad and is not suitable when we have an interest in a particular fixture. In the next chapter, we shall narrow down to a specific fixture of interest.
However, before we do so, we will make our response more human-readable.
Chapter 2.2 Making our response readable.
In this section, we shall have the JSON response formatted properly using the code block below.
match serde_json::to_string_pretty(&json) { Ok(pretty_json) => println!("{}", pretty_json), Err(e) => eprintln!("Failed to pretty-print JSON: {}", e),... }
serde_json::to_string_pretty: Converts the Value into a nicely formatted string with indentation while ‘match’ handles potential errors during pretty-printing.
Ok(pretty_json): Prints the formatted JSON if successful, while Err(e): Prints an error message if pretty-printing fails.
Here is the full code below.
use reqwest::Error; use serde_json::Value; #[tokio::main] async fn main() -> Result<(), Error> { let api_token = "API_Token"; // Replace "API_Token" with your actual API token let url = format!( "https://api.sportmonks.com/v3/football/commentaries?api_token={}", api_token ); // Send the GET request let response = reqwest::get(&url).await?; // Check if the request was successful if response.status().is_success() { // Parse the JSON response let json: Value = response.json().await?; // Try to pretty-print the JSON response match serde_json::to_string_pretty(&json) { Ok(pretty_json) => println!("{}", pretty_json), Err(e) => eprintln!("Failed to pretty-print JSON: {}", e), } } else { // Print an error message if the request failed eprintln!("Failed to fetch data: {}", response.status()); } Ok(()) }
{ "data": [ { "comment": "First Half starts.", "extra_minute": null, "fixture_id": 18444499, "id": 1, "is_goal": false, "is_important": false, "minute": null, "order": 1 }, { "comment": "Corner - Brisbane Roar FC. Conceded by Nicholas Pennington.", "extra_minute": null, "fixture_id": 18444499, "id": 2, "is_goal": false, "is_important": false, "minute": 2, "order": 2 }, { "comment": "Shot blocked. Ryo Wada - Brisbane Roar FC - shot with left foot from outside the box is blocked.", "extra_minute": null, "fixture_id": 18444499, "id": 3, "is_goal": false, "is_important": false, "minute": 7, "order": 3 }, { "comment": "Corner - Brisbane Roar FC. Conceded by Finn Surman.", "extra_minute": null, "fixture_id": 18444499, "id": 5, "is_goal": false, "is_important": false, "minute": 8, "order": 5 }, { "comment": "Shot blocked. David Ball - Wellington Phoenix - shot with left foot from the centre of the box is blocked.", "extra_minute": null, "fixture_id": 18444499, "id": 8, "is_goal": false, "is_important": false, "minute": 13, "order": 8 }, { "comment": "Fouled by James McGarry - Wellington Phoenix", "extra_minute": null, "fixture_id": 18444499, "id": 9, "is_goal": false, "is_important": false, "minute": 13, "order": 9 }, { "comment": "Ryo Wada - Brisbane Roar FC - won a free kick in defence.", "extra_minute": null, "fixture_id": 18444499, "id": 10, "is_goal": false, "is_important": false, "minute": 13, "order": 10 }, { "comment": "Missed chance. Luke Ivanovic - Brisbane Roar FC - shot with right foot from outside the box is high and wide to the right. Assist - Anton Mlinaric.", "extra_minute": null, "fixture_id": 18444499, "id": 11, "is_goal": false, "is_important": false, "minute": 14, "order": 11 }, { "comment": "Luke Ivanovic - Brisbane Roar FC - receive yellow card for a foul.", "extra_minute": null, "fixture_id": 18444499, "id": 14, "is_goal": false, "is_important": true, "minute": 17, "order": 14 }, { "comment": "Missed chance. Juan Eduardo Lescano - Brisbane Roar FC - shot with right foot from the centre of the box.", "extra_minute": null, "fixture_id": 18444499, "id": 15, "is_goal": false, "is_important": false, "minute": 20, "order": 15 }, { "comment": "New attacking attempt. David Ball - Wellington Phoenix - shot with right foot from the left side of the box is saved.", "extra_minute": null, "fixture_id": 18444499, "id": 16, "is_goal": false, "is_important": false, "minute": 21, "order": 16 }, { "comment": "Fouled by Luke Ivanovic - Brisbane Roar FC", "extra_minute": null, "fixture_id": 18444499, "id": 17, "is_goal": false, "is_important": false, "minute": 22, "order": 17 }, { "comment": "Louis Fenton - Wellington Phoenix - won a free kick in defence.", "extra_minute": null, "fixture_id": 18444499, "id": 18, "is_goal": false, "is_important": false, "minute": 22, "order": 18 }, { "comment": "Shot blocked. Nicholas Olsen - Brisbane Roar FC - shot with right foot from the left side of the box is blocked.", "extra_minute": null, "fixture_id": 18444499, "id": 19, "is_goal": false, "is_important": false, "minute": 25, "order": 19 }, { "comment": "New attacking attempt. Ryo Wada - Brisbane Roar FC - shot with left foot from the centre of the box is saved in the right corner. Assist - Nicholas Olsen with a cross.", "extra_minute": null, "fixture_id": 18444499, "id": 20, "is_goal": false, "is_important": false, "minute": 25, "order": 20 }, { "comment": "Corner - Wellington Phoenix. Conceded by Scott Neville.", "extra_minute": null, "fixture_id": 18444499, "id": 21, "is_goal": false, "is_important": false, "minute": 27, "order": 21 }, { "comment": "Missed chance. Ben Waine - Wellington Phoenix - with an attempt from few metres after corner.", "extra_minute": null, "fixture_id": 18444499, "id": 22, "is_goal": false, "is_important": false, "minute": 28, "order": 22 }, { "comment": "Own Goal by Scott Neville, Brisbane Roar FC. Brisbane Roar FC 0, Wellington Phoenix 1.", "extra_minute": null, "fixture_id": 18444499, "id": 23, "is_goal": true, "is_important": true, "minute": 28, "order": 23 }, { "comment": "Matti Steinmann - Brisbane Roar FC - won a free kick in attack.", "extra_minute": null, "fixture_id": 18444499, "id": 25, "is_goal": false, "is_important": false, "minute": 33, "order": 25 }, { "comment": "Missed chance. Kai Trewin - Brisbane Roar FC - shot with the head from the centre of the box goes high. Assist - Nicholas Olsen with a head.", "extra_minute": null, "fixture_id": 18444499, "id": 26, "is_goal": false, "is_important": false, "minute": 34, "order": 26 }, { "comment": "Fouled by Gael Sandoval - Wellington Phoenix", "extra_minute": null, "fixture_id": 18444499, "id": 27, "is_goal": false, "is_important": false, "minute": 36, "order": 27 }, { "comment": "Luke Ivanovic - Brisbane Roar FC - won a free kick on the left wing.", "extra_minute": null, "fixture_id": 18444499, "id": 28, "is_goal": false, "is_important": false, "minute": 36, "order": 28 }, { "comment": "Missed chance. Juan Eduardo Lescano - Brisbane Roar FC - header inside of six yard box - left side.", "extra_minute": null, "fixture_id": 18444499, "id": 29, "is_goal": false, "is_important": false, "minute": 37, "order": 29 }, { "comment": "Corner - Brisbane Roar FC. Conceded by James McGarry.", "extra_minute": null, "fixture_id": 18444499, "id": 31, "is_goal": false, "is_important": false, "minute": 37, "order": 31 }, { "comment": "Corner - Brisbane Roar FC. Conceded by Benjamin Old.", "extra_minute": null, "fixture_id": 18444499, "id": 32, "is_goal": false, "is_important": false, "minute": 38, "order": 32 } ], "pagination": { "count": 25, "current_page": 1, "has_more": true, "next_page": "https://api.sportmonks.com/v3/football/commentaries?page=2", "per_page": 25 }, "rate_limit": { "remaining": 2999, "requested_entity": "Commentary", "resets_in_seconds": 3600 }, "subscription": [ { "add_ons": [ { "add_on": "All-in News API", "category": "News", "sport": "Football" }, { "add_on": "pressure index add-on", "category": "Default", "sport": "Football" }, { "add_on": "Enterprise Plan Predictions", "category": "Predictions", "sport": "Football" }, { "add_on": "xG Advanced", "category": "Expected", "sport": "Football" } ], "meta": { "current_timestamp": 1736007979, "ends_at": null, "trial_ends_at": "2024-10-16 14:50:45" }, "plans": [ { "category": "Advanced", "plan": "Enterprise plan (loyal)", "sport": "Football" }, { "category": "Standard", "plan": "Enterprise Plan", "sport": "Cricket" }, { "category": "Standard", "plan": "Formula One", "sport": "Formula One" } ], "widgets": [ { "sport": "Football", "widget": "Sportmonks Widgets" } ] } ], "timezone": "UTC" }
CHAPTER 3: EXPLORING MATCH COMMENTARIES FROM SINGLE FIXTURES.
Just like we mentioned earlier, in this chapter we shall focus on commentaries from a single fixture.
For our short exercise we shall use the fixture ID 19134638, which is for the Manchester derby that ended in an Amad Diallo-inspired 2-1 win for the Red Devils following an 88th-minute comeback.
3.1 Retrieving Match Commentaries from Specific Fixtures.
Using the base https://api.sportmonks.com/v3/football/commentaries/fixtures/{ID}?api_token=YOUR_TOKEN
We can retrieve the play-by-play action from a specific fixture in Rust using the sample code below.
use reqwest::Error; use serde_json::Value; #[tokio::main] async fn main() -> Result<(), Error> { let api_token = "API_Token"; // Replace "API_Token" with your actual API token let url = format!( "https://api.sportmonks.com/v3/football/commentaries/fixtures/19134638?api_token={}", api_token ); // Send the GET request let response = reqwest::get(&url).await?; // Check if the request was successful if response.status().is_success() { // Parse the JSON response let json: Value = response.json().await?; // Try to pretty-print the JSON response match serde_json::to_string_pretty(&json) { Ok(pretty_json) => println!("{}", pretty_json), Err(e) => eprintln!("Failed to pretty-print JSON: {}", e), } } else { // Print an error message if the request failed eprintln!("Failed to fetch data: {}", response.status()); } Ok(()) }
{ "data": [ { "comment": "Match is currently on hold due to an injury to Mason Mount from Manchester United.", "extra_minute": null, "fixture_id": 19134638, "id": 8833283, "is_goal": false, "is_important": false, "minute": 12, "order": 10 }, { "comment": "Kevin De Bruyne of Manchester City has been awarded a free kick in the defensive area.", "extra_minute": null, "fixture_id": 19134638, "id": 8833210, "is_goal": false, "is_important": false, "minute": 2, "order": 3 }, { "comment": "The opening half is underway...", "extra_minute": null, "fixture_id": 19134638, "id": 8833208, "is_goal": false, "is_important": false, "minute": null, "order": 1 }, { "comment": "Matheus Nunes from Manchester City has been awarded a free kick on the left flank.", "extra_minute": null, "fixture_id": 19134638, "id": 8833242, "is_goal": false, "is_important": false, "minute": 3, "order": 5 }, { "comment": "Fouled by Manuel Ugarte - Manchester United. \n\nRephrased: Manuel Ugarte commits a foul against a Manchester United player.", "extra_minute": null, "fixture_id": 19134638, "id": 8833231, "is_goal": false, "is_important": false, "minute": 4, "order": 6 }, { "comment": "Offside call against Manchester United. Amad Diallo has been flagged for offside.", "extra_minute": null, "fixture_id": 19134638, "id": 8833268, "is_goal": false, "is_important": false, "minute": 11, "order": 9 }, { "comment": "Jérémy Doku from Manchester City has been awarded a free kick in the defensive area.", "extra_minute": null, "fixture_id": 19134638, "id": 8833232, "is_goal": false, "is_important": false, "minute": 4, "order": 7 }, { "comment": "Corner awarded to Manchester City after Lisandro Martínez allowed the ball to go out.", "extra_minute": null, "fixture_id": 19134638, "id": 8833233, "is_goal": false, "is_important": false, "minute": 5, "order": 8 }, { "comment": "Noussair Mazraoui commits a foul against Manchester United.", "extra_minute": null, "fixture_id": 19134638, "id": 8833307, "is_goal": false, "is_important": false, "minute": 15, "order": 13 }, { "comment": "Diogo Dalot from Manchester United committed a foul.", "extra_minute": null, "fixture_id": 19134638, "id": 8833209, "is_goal": false, "is_important": false, "minute": 2, "order": 2 }, { "comment": "Josko Gvardiol from Manchester City earned a free kick on the left side of the field.", "extra_minute": null, "fixture_id": 19134638, "id": 8833308, "is_goal": false, "is_important": false, "minute": 15, "order": 14 }, { "comment": "Fouled by Rasmus Højlund - Manchester United", "extra_minute": null, "fixture_id": 19134638, "id": 8833220, "is_goal": false, "is_important": false, "minute": 3, "order": 4 }, { "comment": "The pause has ended. They’re set to resume play.", "extra_minute": null, "fixture_id": 19134638, "id": 8833305, "is_goal": false, "is_important": false, "minute": 14, "order": 11 }, { "comment": "Substitution for Manchester United: Kobbie Mainoo comes on to replace Mason Mount due to an injury.", "extra_minute": null, "fixture_id": 19134638, "id": 8833306, "is_goal": false, "is_important": false, "minute": 14, "order": 12 }, { "comment": "Fouled by Manuel Ugarte - Manchester United", "extra_minute": 1, "fixture_id": 19134638, "id": 8833568, "is_goal": false, "is_important": false, "minute": 45, "order": 44 }, { "comment": "Missed chance. Phil Foden - Manchester City - shot with left foot from outside the box is close, but missed.", "extra_minute": null, "fixture_id": 19134638, "id": 8833358, "is_goal": false, "is_important": false, "minute": 21, "order": 15 }, { "comment": "Shot blocked. Phil Foden - Manchester City - shot with left foot from the right side of the box is blocked. Assist - Erling Haaland.", "extra_minute": null, "fixture_id": 19134638, "id": 8833375, "is_goal": false, "is_important": false, "minute": 23, "order": 16 }, { "comment": "Corner awarded to Manchester City after Harry Maguire gave it away.", "extra_minute": null, "fixture_id": 19134638, "id": 8833376, "is_goal": false, "is_important": false, "minute": 23, "order": 17 }, { "comment": "Missed chance. Rúben Dias - Manchester City - shot with the head from few metres goes high. Assist - Phil Foden with a cross after corner.", "extra_minute": null, "fixture_id": 19134638, "id": 8833377, "is_goal": false, "is_important": false, "minute": 23, "order": 18 }, { "comment": "Ilkay Gündogan from Manchester City committed a foul.", "extra_minute": null, "fixture_id": 19134638, "id": 8833812, "is_goal": false, "is_important": false, "minute": 53, "order": 59 }, { "comment": "Corner kick awarded to Manchester City after Matthijs de Ligt allowed the ball to go out of play.", "extra_minute": null, "fixture_id": 19134638, "id": 8833813, "is_goal": false, "is_important": false, "minute": 53, "order": 60 }, { "comment": "Bruno Fernandes from Manchester United committed a foul.", "extra_minute": null, "fixture_id": 19134638, "id": 8833466, "is_goal": false, "is_important": false, "minute": 35, "order": 26 }, { "comment": "Offside call against Manchester United. Amad Diallo has been flagged for being offside.", "extra_minute": null, "fixture_id": 19134638, "id": 8833402, "is_goal": false, "is_important": false, "minute": 26, "order": 19 }, { "comment": "Matheus Nunes from Manchester City has been awarded a free kick in the defensive area.", "extra_minute": null, "fixture_id": 19134638, "id": 8833815, "is_goal": false, "is_important": false, "minute": 54, "order": 62 }, { "comment": "Erling Haaland commits a foul for Manchester City.", "extra_minute": null, "fixture_id": 19134638, "id": 8833415, "is_goal": false, "is_important": false, "minute": 29, "order": 20 }, { "comment": "Harry Maguire from Manchester United has earned a free kick in the defensive area.", "extra_minute": null, "fixture_id": 19134638, "id": 8833416, "is_goal": false, "is_important": false, "minute": 29, "order": 21 }, { "comment": "The second half is underway with the score at Manchester City 1, Manchester United 0.", "extra_minute": null, "fixture_id": 19134638, "id": 8833744, "is_goal": false, "is_important": false, "minute": 45, "order": 51 }, { "comment": "The attempt is deflected. Lisandro Martínez of Manchester United takes a left-footed shot from outside the penalty area, but it is blocked. The assist came from Manuel Ugarte.", "extra_minute": null, "fixture_id": 19134638, "id": 8833434, "is_goal": false, "is_important": false, "minute": 32, "order": 22 }, { "comment": "Missed opportunity. Manuel Ugarte from Manchester United attempted a right-footed shot from outside the penalty area, but it sailed high and to the right of the goal. The assist came from Kobbie Mainoo.", "extra_minute": null, "fixture_id": 19134638, "id": 8833435, "is_goal": false, "is_important": false, "minute": 32, "order": 23 }, { "comment": "Shot blocked. Amad Diallo - Manchester United - shot with left foot from the right side of the box is blocked.", "extra_minute": null, "fixture_id": 19134638, "id": 8833436, "is_goal": false, "is_important": false, "minute": 35, "order": 24 }, { "comment": "Bernardo Silva - Manchester City - won a free kick on the right wing.", "extra_minute": null, "fixture_id": 19134638, "id": 8833437, "is_goal": false, "is_important": false, "minute": 35, "order": 25 }, { "comment": "Corner awarded to Manchester City after André Onana allowed the ball to go out.", "extra_minute": 4, "fixture_id": 19134638, "id": 8833598, "is_goal": false, "is_important": false, "minute": 45, "order": 47 }, { "comment": "Kevin De Bruyne from Manchester City has been awarded a free kick on the left flank.", "extra_minute": 4, "fixture_id": 19134638, "id": 8833600, "is_goal": false, "is_important": false, "minute": 45, "order": 49 }, { "comment": "A shot is deflected! Jérémy Doku of Manchester City attempts a right-footed strike from the left side of the penalty area, but it's blocked. The assist came from Phil Foden.", "extra_minute": null, "fixture_id": 19134638, "id": 8833461, "is_goal": false, "is_important": false, "minute": 36, "order": 27 }, { "comment": "Corner awarded to Manchester City after Noussair Mazraoui allowed the ball to go out of play.", "extra_minute": null, "fixture_id": 19134638, "id": 8833462, "is_goal": false, "is_important": false, "minute": 36, "order": 28 }, { "comment": "Goal! Manchester City takes the lead with a score of 1-0 against Manchester United. Josko Gvardiol heads the ball into the center of the net from the middle of the box following a corner kick.", "extra_minute": null, "fixture_id": 19134638, "id": 8833463, "is_goal": true, "is_important": true, "minute": 36, "order": 29 }, { "comment": "The attempt is thwarted. Amad Diallo of Manchester United takes a left-footed shot from outside the penalty area, but it gets blocked. The assist came from Bruno Fernandes.", "extra_minute": null, "fixture_id": 19134638, "id": 8833783, "is_goal": false, "is_important": false, "minute": 50, "order": 53 }, { "comment": "Manuel Ugarte commits a foul on a Manchester United player.", "extra_minute": null, "fixture_id": 19134638, "id": 8833785, "is_goal": false, "is_important": false, "minute": 50, "order": 55 }, { "comment": "Bruno Fernandes from Manchester United has earned a free kick in the defensive area.", "extra_minute": null, "fixture_id": 19134638, "id": 8833811, "is_goal": false, "is_important": false, "minute": 53, "order": 58 }, { "comment": "Kyle Walker from Manchester City committed a foul.", "extra_minute": null, "fixture_id": 19134638, "id": 8833504, "is_goal": false, "is_important": false, "minute": 38, "order": 30 }, { "comment": "Rasmus Højlund from Manchester United earned a free kick in an offensive position.", "extra_minute": null, "fixture_id": 19134638, "id": 8833505, "is_goal": false, "is_important": false, "minute": 38, "order": 31 }, { "comment": "Kyle Walker from Manchester City has been shown a yellow card.", "extra_minute": null, "fixture_id": 19134638, "id": 8833507, "is_goal": false, "is_important": true, "minute": 40, "order": 33 }, { "comment": "Rasmus Højlund of Manchester United has been shown a yellow card.", "extra_minute": null, "fixture_id": 19134638, "id": 8833506, "is_goal": false, "is_important": true, "minute": 40, "order": 32 }, { "comment": "Missed chance. Matthijs de Ligt - Manchester United - shot with the head from the centre of the box missed to the left. Assist - Bruno Fernandes .", "extra_minute": null, "fixture_id": 19134638, "id": 8833508, "is_goal": false, "is_important": false, "minute": 40, "order": 34 }, { "comment": "Offside call against Manchester United. Noussair Mazraoui has been caught offside.", "extra_minute": null, "fixture_id": 19134638, "id": 8833745, "is_goal": false, "is_important": false, "minute": 47, "order": 52 }, { "comment": "Corner awarded to Manchester United after Ederson allowed the ball to go out.", "extra_minute": null, "fixture_id": 19134638, "id": 8833896, "is_goal": false, "is_important": false, "minute": 62, "order": 68 }, { "comment": "Corner - Manchester United. Conceded by Rúben Dias.", "extra_minute": null, "fixture_id": 19134638, "id": 8833528, "is_goal": false, "is_important": false, "minute": 40, "order": 35 }, { "comment": "Offside - Manchester United. Diogo Dalot is in offside.", "extra_minute": null, "fixture_id": 19134638, "id": 8833529, "is_goal": false, "is_important": false, "minute": 41, "order": 36 }, { "comment": "Fourth official has announced 4 minutes of added time.", "extra_minute": null, "fixture_id": 19134638, "id": 8833567, "is_goal": false, "is_important": false, "minute": 45, "order": 43 }, { "comment": "Lisandro Martínez from Manchester United committed a foul.", "extra_minute": 4, "fixture_id": 19134638, "id": 8833599, "is_goal": false, "is_important": false, "minute": 45, "order": 48 }, { "comment": "The first half has concluded with Manchester City leading Manchester United 1-0.", "extra_minute": 5, "fixture_id": 19134638, "id": 8833601, "is_goal": false, "is_important": false, "minute": 45, "order": 50 }, { "comment": "Delay in match - Manchester City", "extra_minute": null, "fixture_id": 19134638, "id": 8833562, "is_goal": false, "is_important": false, "minute": 43, "order": 38 }, { "comment": "Delay over. They are ready to continue.", "extra_minute": null, "fixture_id": 19134638, "id": 8833563, "is_goal": false, "is_important": false, "minute": 43, "order": 39 }, { "comment": "New attacking attempt. Kevin De Bruyne - Manchester City - shot with right foot from long distance on the right is saved in the top right corner.", "extra_minute": null, "fixture_id": 19134638, "id": 8833561, "is_goal": false, "is_important": false, "minute": 43, "order": 37 }, { "comment": "Offside - Manchester United. Amad Diallo is in offside.", "extra_minute": null, "fixture_id": 19134638, "id": 8833564, "is_goal": false, "is_important": false, "minute": 44, "order": 40 }, { "comment": "Fouled by Erling Haaland - Manchester City", "extra_minute": null, "fixture_id": 19134638, "id": 8833565, "is_goal": false, "is_important": false, "minute": 45, "order": 41 }, { "comment": "Manuel Ugarte - Manchester United - won a free kick in defence.", "extra_minute": null, "fixture_id": 19134638, "id": 8833566, "is_goal": false, "is_important": false, "minute": 45, "order": 42 }, { "comment": "Kevin De Bruyne from Manchester City has earned a free kick on the right side of the field.", "extra_minute": 1, "fixture_id": 19134638, "id": 8833596, "is_goal": false, "is_important": false, "minute": 45, "order": 45 }, { "comment": "Another offensive push from Manchester City. Phil Foden takes a left-footed shot from outside the penalty area, but it's saved in the bottom left corner. The assist came from Ilkay Gündogan.", "extra_minute": 4, "fixture_id": 19134638, "id": 8833597, "is_goal": false, "is_important": false, "minute": 45, "order": 46 }, { "comment": "Bernardo Silva - Manchester City - won a free kick in attack.", "extra_minute": null, "fixture_id": 19134638, "id": 8833897, "is_goal": false, "is_important": false, "minute": 66, "order": 69 }, { "comment": "Matheus Nunes from Manchester City has given away a penalty due to a foul committed inside the box.", "extra_minute": null, "fixture_id": 19134638, "id": 8834011, "is_goal": false, "is_important": false, "minute": 86, "order": 87 }, { "comment": "Kobbie Mainoo from Manchester United committed a foul.", "extra_minute": null, "fixture_id": 19134638, "id": 8833845, "is_goal": false, "is_important": false, "minute": 58, "order": 63 }, { "comment": "Missed chance. Kobbie Mainoo - Manchester United - shot with the head from the centre of the box goes high. Assist - Lisandro Martínez with a cross.", "extra_minute": null, "fixture_id": 19134638, "id": 8834007, "is_goal": false, "is_important": false, "minute": 84, "order": 84 }, { "comment": "Penalty awarded to Manchester United! Amad Diallo is fouled inside the box.", "extra_minute": null, "fixture_id": 19134638, "id": 8834010, "is_goal": false, "is_important": false, "minute": 86, "order": 86 }, { "comment": "Diogo Dalot commits a foul for Manchester United.", "extra_minute": null, "fixture_id": 19134638, "id": 8833787, "is_goal": false, "is_important": false, "minute": 51, "order": 57 }, { "comment": "Bernardo Silva from Manchester City has been awarded a free kick in the defensive area.", "extra_minute": null, "fixture_id": 19134638, "id": 8833786, "is_goal": false, "is_important": false, "minute": 51, "order": 56 }, { "comment": "Diogo Dalot of Manchester United committed a foul.", "extra_minute": null, "fixture_id": 19134638, "id": 8833814, "is_goal": false, "is_important": false, "minute": 54, "order": 61 }, { "comment": "Matheus Nunes from Manchester City earned a free kick on the left flank.", "extra_minute": null, "fixture_id": 19134638, "id": 8833846, "is_goal": false, "is_important": false, "minute": 58, "order": 64 }, { "comment": "Fouled by Noussair Mazraoui of Manchester United.", "extra_minute": null, "fixture_id": 19134638, "id": 8833869, "is_goal": false, "is_important": false, "minute": 58, "order": 65 }, { "comment": "Bernardo Silva from Manchester City has earned a free kick in the defensive zone.", "extra_minute": null, "fixture_id": 19134638, "id": 8833784, "is_goal": false, "is_important": false, "minute": 50, "order": 54 }, { "comment": "Substitution for Manchester United: Leny Yoro comes on to replace Matthijs de Ligt.", "extra_minute": null, "fixture_id": 19134638, "id": 8833984, "is_goal": false, "is_important": false, "minute": 79, "order": 83 }, { "comment": "Manuel Ugarte commits a foul against Manchester United.", "extra_minute": null, "fixture_id": 19134638, "id": 8833905, "is_goal": false, "is_important": false, "minute": 66, "order": 70 }, { "comment": "Goal! Manchester City 1, Manchester United 2. Amad Diallo from Manchester United takes a left-footed shot from a challenging angle on the left side, sending the ball towards the center of the goal. The assist comes from Lisandro Martínez, who delivered a precise through ball.", "extra_minute": null, "fixture_id": 19134638, "id": 8834036, "is_goal": true, "is_important": true, "minute": 90, "order": 92 }, { "comment": "Another offensive push from Manchester United. Amad Diallo heads the ball from the center of the box, but it's expertly saved in the right corner. The assist came from Bruno Fernandes, who delivered a precise cross.", "extra_minute": null, "fixture_id": 19134638, "id": 8833887, "is_goal": false, "is_important": false, "minute": 62, "order": 67 }, { "comment": "Substitution for Manchester City: Savinho is coming on to replace Ilkay Gündogan.", "extra_minute": null, "fixture_id": 19134638, "id": 8834035, "is_goal": false, "is_important": false, "minute": 89, "order": 91 }, { "comment": "Opportunity wasted. Kevin De Bruyne from Manchester City takes a left-footed shot from outside the penalty area, but it sails over the crossbar.", "extra_minute": null, "fixture_id": 19134638, "id": 8833914, "is_goal": false, "is_important": false, "minute": 67, "order": 71 }, { "comment": "Substitution for Manchester City: Mateo Kovacic is coming on to replace Kevin De Bruyne.", "extra_minute": null, "fixture_id": 19134638, "id": 8833915, "is_goal": false, "is_important": false, "minute": 68, "order": 72 }, { "comment": "Substitution for Manchester United: Joshua Zirkzee comes on to replace Rasmus Højlund.", "extra_minute": null, "fixture_id": 19134638, "id": 8833982, "is_goal": false, "is_important": false, "minute": 78, "order": 81 }, { "comment": "Corner awarded to Manchester City after Kobbie Mainoo allowed the ball to go out.", "extra_minute": null, "fixture_id": 19134638, "id": 8834009, "is_goal": false, "is_important": false, "minute": 84, "order": 85 }, { "comment": "Substitution for Manchester City: Jack Grealish comes off, and Jérémy Doku takes his place.", "extra_minute": null, "fixture_id": 19134638, "id": 8833980, "is_goal": false, "is_important": false, "minute": 77, "order": 79 }, { "comment": "The fourth official has indicated that there will be 5 minutes of stoppage time.", "extra_minute": null, "fixture_id": 19134638, "id": 8834037, "is_goal": false, "is_important": false, "minute": 90, "order": 93 }, { "comment": "Corner awarded to Manchester City after Lisandro Martínez allowed the ball to go out.", "extra_minute": null, "fixture_id": 19134638, "id": 8833979, "is_goal": false, "is_important": false, "minute": 76, "order": 78 }, { "comment": "Goal! Manchester City 1, Manchester United 1. Bruno Fernandes - Manchester United - converts the penalty with a shot with right foot to the right corner.", "extra_minute": null, "fixture_id": 19134638, "id": 8834022, "is_goal": true, "is_important": true, "minute": 88, "order": 90 }, { "comment": "Opportunity squandered. Phil Foden of Manchester City takes a left-footed shot from outside the penalty area following a corner, but it sails over the goal.", "extra_minute": null, "fixture_id": 19134638, "id": 8833981, "is_goal": false, "is_important": false, "minute": 78, "order": 80 }, { "comment": "Offside call against Manchester United. Rasmus Højlund has been flagged for being in an offside position.", "extra_minute": null, "fixture_id": 19134638, "id": 8833946, "is_goal": false, "is_important": false, "minute": 72, "order": 73 }, { "comment": "Bernardo Silva from Manchester City has been awarded a free kick on the right flank.", "extra_minute": null, "fixture_id": 19134638, "id": 8833947, "is_goal": false, "is_important": false, "minute": 73, "order": 74 }, { "comment": "Diogo Dalot of Manchester United committed a foul.", "extra_minute": null, "fixture_id": 19134638, "id": 8833948, "is_goal": false, "is_important": false, "minute": 73, "order": 75 }, { "comment": "Missed chance. Bruno Fernandes - Manchester United - shot with right foot from the right side of the box is close, but missed to the left. Assist - Rasmus Højlund with a through ball following a fast break.", "extra_minute": null, "fixture_id": 19134638, "id": 8833950, "is_goal": false, "is_important": false, "minute": 74, "order": 76 }, { "comment": "The attempt is denied. Erling Haaland from Manchester City fires a left-footed shot from the middle of the penalty area, but it's intercepted. The assist came from Mateo Kovacic.", "extra_minute": null, "fixture_id": 19134638, "id": 8833978, "is_goal": false, "is_important": false, "minute": 76, "order": 77 }, { "comment": "Substitution for Manchester United: Antony replaces Noussair Mazraoui.", "extra_minute": null, "fixture_id": 19134638, "id": 8833983, "is_goal": false, "is_important": false, "minute": 78, "order": 82 }, { "comment": "The second half has concluded with the final score: Manchester City 1, Manchester United 2.", "extra_minute": 6, "fixture_id": 19134638, "id": 8834061, "is_goal": false, "is_important": false, "minute": 90, "order": 96 }, { "comment": "Delay in match - injury Amad Diallo - Manchester United", "extra_minute": null, "fixture_id": 19134638, "id": 8834018, "is_goal": false, "is_important": false, "minute": 86, "order": 88 }, { "comment": "Corner awarded to Manchester City after Victor Lindelöf allowed the ball to go out.", "extra_minute": 5, "fixture_id": 19134638, "id": 8834060, "is_goal": false, "is_important": false, "minute": 90, "order": 95 }, { "comment": "The pause has ended. They are set to resume play.", "extra_minute": null, "fixture_id": 19134638, "id": 8834020, "is_goal": false, "is_important": false, "minute": 87, "order": 89 }, { "comment": "That's it! The match has concluded with Manchester City 1, Manchester United 2.", "extra_minute": null, "fixture_id": 19134638, "id": 8834062, "is_goal": false, "is_important": false, "minute": null, "order": 97 }, { "comment": "Substitution for Manchester United: Victor Lindelöf comes on to replace Amad Diallo.", "extra_minute": 1, "fixture_id": 19134638, "id": 8834049, "is_goal": false, "is_important": false, "minute": 90, "order": 94 } ], "rate_limit": { "remaining": 2997, "requested_entity": "Commentary", "resets_in_seconds": 410 }, "subscription": [ { "add_ons": [ { "add_on": "All-in News API", "category": "News", "sport": "Football" }, { "add_on": "pressure index add-on", "category": "Default", "sport": "Football" }, { "add_on": "Enterprise Plan Predictions", "category": "Predictions", "sport": "Football" }, { "add_on": "xG Advanced", "category": "Expected", "sport": "Football" } ], "meta": { "current_timestamp": 1736011169, "ends_at": null, "trial_ends_at": "2024-10-16 14:50:45" }, "plans": [ { "category": "Advanced", "plan": "Enterprise plan (loyal)", "sport": "Football" }, { "category": "Standard", "plan": "Enterprise Plan", "sport": "Cricket" }, { "category": "Standard", "plan": "Formula One", "sport": "Formula One" } ], "widgets": [ { "sport": "Football", "widget": "Sportmonks Widgets" } ] } ], "timezone": "UTC" }
3.2 Order Match Commentaries in Descending Order.
You must have noticed the results are not arranged in any particular order. However, since this is a live, minute-by-minute coverage, it would be ideal to arrange the commentaries in an orderly fashion.
To achieve this, we shall rearrange the commentaries in descending order using the field rightly named ‘order.’
We shall introduce a new code section to sort the commentaries using the order field.
if let Some(data) = json.get("data") { let mut commentaries: Vec = serde_json::from_value(data.clone())?; // Sorting the commentaries by the "order" field in descending order commentaries.sort_by(|a, b| b.order.cmp(&a.order)); // Convert sorted vector back to JSON let sorted_json = serde_json::to_string_pretty(&commentaries)?; println!("{}", sorted_json); }
Using b.order.cmp(&a.order) ensures the largest order value comes first to enable us arrange the commentaries by Descending Order.
Rust’s sort_by ensures optimal performance even with large datasets. After sorting the vector, it is serialized back into JSON format using serde_json::to_string_pretty as shown in the piece of code.
Here below is the full code.
use reqwest::Error; use serde::{Deserialize, Serialize}; use serde_json::Value; #[derive(Debug, Deserialize, Serialize)] struct Commentary { comment: String, extra_minute: Option<i32>, fixture_id: i64, id: i64, is_goal: bool, is_important: bool, minute: Option<i32>, order: i32, } #[tokio::main] async fn main() -> Result<(), Error> { // Replace "API_Token" with your actual API token let api_token = "API_Token"; let url = format!( "https://api.sportmonks.com/v3/football/commentaries/fixtures/19134638?api_token={}", api_token ); // Send the GET request let response = reqwest::get(&url).await?; if response.status().is_success() { // Parse the JSON response let json: Value = response.json().await?; // Extract the "data" field which contains the list of commentaries if let Some(data) = json.get("data") { // Deserialize into a Vec<Commentary> let mut commentaries: Vec<Commentary> = serde_json::from_value(data.clone()) .expect("Failed to deserialize 'data' field into Vec<Commentary>"); // Sort the commentaries by the "order" field in descending order commentaries.sort_by(|a, b| b.order.cmp(&a.order)); // Serialize the sorted list back to JSON let sorted_json = serde_json::to_string_pretty(&commentaries) .expect("Failed to serialize sorted commentaries to JSON"); println!("{}", sorted_json); } else { eprintln!("The 'data' field is missing in the response."); } } else { eprintln!("Failed to fetch data: {}", response.status()); } Ok(()) }
[ { "comment": "That's it! The match has concluded with Manchester City 1, Manchester United 2.", "extra_minute": null, "fixture_id": 19134638, "id": 8834062, "is_goal": false, "is_important": false, "minute": null, "order": 97 }, { "comment": "The second half has concluded with the final score: Manchester City 1, Manchester United 2.", "extra_minute": 6, "fixture_id": 19134638, "id": 8834061, "is_goal": false, "is_important": false, "minute": 90, "order": 96 }, { "comment": "Corner awarded to Manchester City after Victor Lindelöf allowed the ball to go out.", "extra_minute": 5, "fixture_id": 19134638, "id": 8834060, "is_goal": false, "is_important": false, "minute": 90, "order": 95 }, { "comment": "Substitution for Manchester United: Victor Lindelöf comes on to replace Amad Diallo.", "extra_minute": 1, "fixture_id": 19134638, "id": 8834049, "is_goal": false, "is_important": false, "minute": 90, "order": 94 }, { "comment": "The fourth official has indicated that there will be 5 minutes of stoppage time.", "extra_minute": null, "fixture_id": 19134638, "id": 8834037, "is_goal": false, "is_important": false, "minute": 90, "order": 93 }, { "comment": "Goal! Manchester City 1, Manchester United 2. Amad Diallo from Manchester United takes a left-footed shot from a challenging angle on the left side, sending the ball towards the center of the goal. The assist comes from Lisandro Martínez, who delivered a precise through ball.", "extra_minute": null, "fixture_id": 19134638, "id": 8834036, "is_goal": true, "is_important": true, "minute": 90, "order": 92 }, { "comment": "Substitution for Manchester City: Savinho is coming on to replace Ilkay Gündogan.", "extra_minute": null, "fixture_id": 19134638, "id": 8834035, "is_goal": false, "is_important": false, "minute": 89, "order": 91 }, { "comment": "Goal! Manchester City 1, Manchester United 1. Bruno Fernandes - Manchester United - converts the penalty with a shot with right foot to the right corner.", "extra_minute": null, "fixture_id": 19134638, "id": 8834022, "is_goal": true, "is_important": true, "minute": 88, "order": 90 }, { "comment": "The pause has ended. They are set to resume play.", "extra_minute": null, "fixture_id": 19134638, "id": 8834020, "is_goal": false, "is_important": false, "minute": 87, "order": 89 }, { "comment": "Delay in match - injury Amad Diallo - Manchester United", "extra_minute": null, "fixture_id": 19134638, "id": 8834018, "is_goal": false, "is_important": false, "minute": 86, "order": 88 }, { "comment": "Matheus Nunes from Manchester City has given away a penalty due to a foul committed inside the box.", "extra_minute": null, "fixture_id": 19134638, "id": 8834011, "is_goal": false, "is_important": false, "minute": 86, "order": 87 }, { "comment": "Penalty awarded to Manchester United! Amad Diallo is fouled inside the box.", "extra_minute": null, "fixture_id": 19134638, "id": 8834010, "is_goal": false, "is_important": false, "minute": 86, "order": 86 }, { "comment": "Corner awarded to Manchester City after Kobbie Mainoo allowed the ball to go out.", "extra_minute": null, "fixture_id": 19134638, "id": 8834009, "is_goal": false, "is_important": false, "minute": 84, "order": 85 }, { "comment": "Missed chance. Kobbie Mainoo - Manchester United - shot with the head from the centre of the box goes high. Assist - Lisandro Martínez with a cross.", "extra_minute": null, "fixture_id": 19134638, "id": 8834007, "is_goal": false, "is_important": false, "minute": 84, "order": 84 }, { "comment": "Substitution for Manchester United: Leny Yoro comes on to replace Matthijs de Ligt.", "extra_minute": null, "fixture_id": 19134638, "id": 8833984, "is_goal": false, "is_important": false, "minute": 79, "order": 83 }, { "comment": "Substitution for Manchester United: Antony replaces Noussair Mazraoui.", "extra_minute": null, "fixture_id": 19134638, "id": 8833983, "is_goal": false, "is_important": false, "minute": 78, "order": 82 }, { "comment": "Substitution for Manchester United: Joshua Zirkzee comes on to replace Rasmus Højlund.", "extra_minute": null, "fixture_id": 19134638, "id": 8833982, "is_goal": false, "is_important": false, "minute": 78, "order": 81 }, { "comment": "Opportunity squandered. Phil Foden of Manchester City takes a left-footed shot from outside the penalty area following a corner, but it sails over the goal.", "extra_minute": null, "fixture_id": 19134638, "id": 8833981, "is_goal": false, "is_important": false, "minute": 78, "order": 80 }, { "comment": "Substitution for Manchester City: Jack Grealish comes off, and Jérémy Doku takes his place.", "extra_minute": null, "fixture_id": 19134638, "id": 8833980, "is_goal": false, "is_important": false, "minute": 77, "order": 79 }, { "comment": "Corner awarded to Manchester City after Lisandro Martínez allowed the ball to go out.", "extra_minute": null, "fixture_id": 19134638, "id": 8833979, "is_goal": false, "is_important": false, "minute": 76, "order": 78 }, { "comment": "The attempt is denied. Erling Haaland from Manchester City fires a left-footed shot from the middle of the penalty area, but it's intercepted. The assist came from Mateo Kovacic.", "extra_minute": null, "fixture_id": 19134638, "id": 8833978, "is_goal": false, "is_important": false, "minute": 76, "order": 77 }, { "comment": "Missed chance. Bruno Fernandes - Manchester United - shot with right foot from the right side of the box is close, but missed to the left. Assist - Rasmus Højlund with a through ball following a fast break.", "extra_minute": null, "fixture_id": 19134638, "id": 8833950, "is_goal": false, "is_important": false, "minute": 74, "order": 76 }, { "comment": "Diogo Dalot of Manchester United committed a foul.", "extra_minute": null, "fixture_id": 19134638, "id": 8833948, "is_goal": false, "is_important": false, "minute": 73, "order": 75 }, { "comment": "Bernardo Silva from Manchester City has been awarded a free kick on the right flank.", "extra_minute": null, "fixture_id": 19134638, "id": 8833947, "is_goal": false, "is_important": false, "minute": 73, "order": 74 }, { "comment": "Offside call against Manchester United. Rasmus Højlund has been flagged for being in an offside position.", "extra_minute": null, "fixture_id": 19134638, "id": 8833946, "is_goal": false, "is_important": false, "minute": 72, "order": 73 }, { "comment": "Substitution for Manchester City: Mateo Kovacic is coming on to replace Kevin De Bruyne.", "extra_minute": null, "fixture_id": 19134638, "id": 8833915, "is_goal": false, "is_important": false, "minute": 68, "order": 72 }, { "comment": "Opportunity wasted. Kevin De Bruyne from Manchester City takes a left-footed shot from outside the penalty area, but it sails over the crossbar.", "extra_minute": null, "fixture_id": 19134638, "id": 8833914, "is_goal": false, "is_important": false, "minute": 67, "order": 71 }, { "comment": "Manuel Ugarte commits a foul against Manchester United.", "extra_minute": null, "fixture_id": 19134638, "id": 8833905, "is_goal": false, "is_important": false, "minute": 66, "order": 70 }, { "comment": "Bernardo Silva - Manchester City - won a free kick in attack.", "extra_minute": null, "fixture_id": 19134638, "id": 8833897, "is_goal": false, "is_important": false, "minute": 66, "order": 69 }, { "comment": "Corner awarded to Manchester United after Ederson allowed the ball to go out.", "extra_minute": null, "fixture_id": 19134638, "id": 8833896, "is_goal": false, "is_important": false, "minute": 62, "order": 68 }, { "comment": "Another offensive push from Manchester United. Amad Diallo heads the ball from the center of the box, but it's expertly saved in the right corner. The assist came from Bruno Fernandes, who delivered a precise cross.", "extra_minute": null, "fixture_id": 19134638, "id": 8833887, "is_goal": false, "is_important": false, "minute": 62, "order": 67 }, { "comment": "Fouled by Noussair Mazraoui of Manchester United.", "extra_minute": null, "fixture_id": 19134638, "id": 8833869, "is_goal": false, "is_important": false, "minute": 58, "order": 65 }, { "comment": "Matheus Nunes from Manchester City earned a free kick on the left flank.", "extra_minute": null, "fixture_id": 19134638, "id": 8833846, "is_goal": false, "is_important": false, "minute": 58, "order": 64 }, { "comment": "Kobbie Mainoo from Manchester United committed a foul.", "extra_minute": null, "fixture_id": 19134638, "id": 8833845, "is_goal": false, "is_important": false, "minute": 58, "order": 63 }, { "comment": "Matheus Nunes from Manchester City has been awarded a free kick in the defensive area.", "extra_minute": null, "fixture_id": 19134638, "id": 8833815, "is_goal": false, "is_important": false, "minute": 54, "order": 62 }, { "comment": "Diogo Dalot of Manchester United committed a foul.", "extra_minute": null, "fixture_id": 19134638, "id": 8833814, "is_goal": false, "is_important": false, "minute": 54, "order": 61 }, { "comment": "Corner kick awarded to Manchester City after Matthijs de Ligt allowed the ball to go out of play.", "extra_minute": null, "fixture_id": 19134638, "id": 8833813, "is_goal": false, "is_important": false, "minute": 53, "order": 60 }, { "comment": "Ilkay Gündogan from Manchester City committed a foul.", "extra_minute": null, "fixture_id": 19134638, "id": 8833812, "is_goal": false, "is_important": false, "minute": 53, "order": 59 }, { "comment": "Bruno Fernandes from Manchester United has earned a free kick in the defensive area.", "extra_minute": null, "fixture_id": 19134638, "id": 8833811, "is_goal": false, "is_important": false, "minute": 53, "order": 58 }, { "comment": "Diogo Dalot commits a foul for Manchester United.", "extra_minute": null, "fixture_id": 19134638, "id": 8833787, "is_goal": false, "is_important": false, "minute": 51, "order": 57 }, { "comment": "Bernardo Silva from Manchester City has been awarded a free kick in the defensive area.", "extra_minute": null, "fixture_id": 19134638, "id": 8833786, "is_goal": false, "is_important": false, "minute": 51, "order": 56 }, { "comment": "Manuel Ugarte commits a foul on a Manchester United player.", "extra_minute": null, "fixture_id": 19134638, "id": 8833785, "is_goal": false, "is_important": false, "minute": 50, "order": 55 }, { "comment": "Bernardo Silva from Manchester City has earned a free kick in the defensive zone.", "extra_minute": null, "fixture_id": 19134638, "id": 8833784, "is_goal": false, "is_important": false, "minute": 50, "order": 54 }, { "comment": "The attempt is thwarted. Amad Diallo of Manchester United takes a left-footed shot from outside the penalty area, but it gets blocked. The assist came from Bruno Fernandes.", "extra_minute": null, "fixture_id": 19134638, "id": 8833783, "is_goal": false, "is_important": false, "minute": 50, "order": 53 }, { "comment": "Offside call against Manchester United. Noussair Mazraoui has been caught offside.", "extra_minute": null, "fixture_id": 19134638, "id": 8833745, "is_goal": false, "is_important": false, "minute": 47, "order": 52 }, { "comment": "The second half is underway with the score at Manchester City 1, Manchester United 0.", "extra_minute": null, "fixture_id": 19134638, "id": 8833744, "is_goal": false, "is_important": false, "minute": 45, "order": 51 }, { "comment": "The first half has concluded with Manchester City leading Manchester United 1-0.", "extra_minute": 5, "fixture_id": 19134638, "id": 8833601, "is_goal": false, "is_important": false, "minute": 45, "order": 50 }, { "comment": "Kevin De Bruyne from Manchester City has been awarded a free kick on the left flank.", "extra_minute": 4, "fixture_id": 19134638, "id": 8833600, "is_goal": false, "is_important": false, "minute": 45, "order": 49 }, { "comment": "Lisandro Martínez from Manchester United committed a foul.", "extra_minute": 4, "fixture_id": 19134638, "id": 8833599, "is_goal": false, "is_important": false, "minute": 45, "order": 48 }, { "comment": "Corner awarded to Manchester City after André Onana allowed the ball to go out.", "extra_minute": 4, "fixture_id": 19134638, "id": 8833598, "is_goal": false, "is_important": false, "minute": 45, "order": 47 }, { "comment": "Another offensive push from Manchester City. Phil Foden takes a left-footed shot from outside the penalty area, but it's saved in the bottom left corner. The assist came from Ilkay Gündogan.", "extra_minute": 4, "fixture_id": 19134638, "id": 8833597, "is_goal": false, "is_important": false, "minute": 45, "order": 46 }, { "comment": "Kevin De Bruyne from Manchester City has earned a free kick on the right side of the field.", "extra_minute": 1, "fixture_id": 19134638, "id": 8833596, "is_goal": false, "is_important": false, "minute": 45, "order": 45 }, { "comment": "Fouled by Manuel Ugarte - Manchester United", "extra_minute": 1, "fixture_id": 19134638, "id": 8833568, "is_goal": false, "is_important": false, "minute": 45, "order": 44 }, { "comment": "Fourth official has announced 4 minutes of added time.", "extra_minute": null, "fixture_id": 19134638, "id": 8833567, "is_goal": false, "is_important": false, "minute": 45, "order": 43 }, { "comment": "Manuel Ugarte - Manchester United - won a free kick in defence.", "extra_minute": null, "fixture_id": 19134638, "id": 8833566, "is_goal": false, "is_important": false, "minute": 45, "order": 42 }, { "comment": "Fouled by Erling Haaland - Manchester City", "extra_minute": null, "fixture_id": 19134638, "id": 8833565, "is_goal": false, "is_important": false, "minute": 45, "order": 41 }, { "comment": "Offside - Manchester United. Amad Diallo is in offside.", "extra_minute": null, "fixture_id": 19134638, "id": 8833564, "is_goal": false, "is_important": false, "minute": 44, "order": 40 }, { "comment": "Delay over. They are ready to continue.", "extra_minute": null, "fixture_id": 19134638, "id": 8833563, "is_goal": false, "is_important": false, "minute": 43, "order": 39 }, { "comment": "Delay in match - Manchester City", "extra_minute": null, "fixture_id": 19134638, "id": 8833562, "is_goal": false, "is_important": false, "minute": 43, "order": 38 }, { "comment": "New attacking attempt. Kevin De Bruyne - Manchester City - shot with right foot from long distance on the right is saved in the top right corner.", "extra_minute": null, "fixture_id": 19134638, "id": 8833561, "is_goal": false, "is_important": false, "minute": 43, "order": 37 }, { "comment": "Offside - Manchester United. Diogo Dalot is in offside.", "extra_minute": null, "fixture_id": 19134638, "id": 8833529, "is_goal": false, "is_important": false, "minute": 41, "order": 36 }, { "comment": "Corner - Manchester United. Conceded by Rúben Dias.", "extra_minute": null, "fixture_id": 19134638, "id": 8833528, "is_goal": false, "is_important": false, "minute": 40, "order": 35 }, { "comment": "Missed chance. Matthijs de Ligt - Manchester United - shot with the head from the centre of the box missed to the left. Assist - Bruno Fernandes .", "extra_minute": null, "fixture_id": 19134638, "id": 8833508, "is_goal": false, "is_important": false, "minute": 40, "order": 34 }, { "comment": "Kyle Walker from Manchester City has been shown a yellow card.", "extra_minute": null, "fixture_id": 19134638, "id": 8833507, "is_goal": false, "is_important": true, "minute": 40, "order": 33 }, { "comment": "Rasmus Højlund of Manchester United has been shown a yellow card.", "extra_minute": null, "fixture_id": 19134638, "id": 8833506, "is_goal": false, "is_important": true, "minute": 40, "order": 32 }, { "comment": "Rasmus Højlund from Manchester United earned a free kick in an offensive position.", "extra_minute": null, "fixture_id": 19134638, "id": 8833505, "is_goal": false, "is_important": false, "minute": 38, "order": 31 }, { "comment": "Kyle Walker from Manchester City committed a foul.", "extra_minute": null, "fixture_id": 19134638, "id": 8833504, "is_goal": false, "is_important": false, "minute": 38, "order": 30 }, { "comment": "Goal! Manchester City takes the lead with a score of 1-0 against Manchester United. Josko Gvardiol heads the ball into the center of the net from the middle of the box following a corner kick.", "extra_minute": null, "fixture_id": 19134638, "id": 8833463, "is_goal": true, "is_important": true, "minute": 36, "order": 29 }, { "comment": "Corner awarded to Manchester City after Noussair Mazraoui allowed the ball to go out of play.", "extra_minute": null, "fixture_id": 19134638, "id": 8833462, "is_goal": false, "is_important": false, "minute": 36, "order": 28 }, { "comment": "A shot is deflected! Jérémy Doku of Manchester City attempts a right-footed strike from the left side of the penalty area, but it's blocked. The assist came from Phil Foden.", "extra_minute": null, "fixture_id": 19134638, "id": 8833461, "is_goal": false, "is_important": false, "minute": 36, "order": 27 }, { "comment": "Bruno Fernandes from Manchester United committed a foul.", "extra_minute": null, "fixture_id": 19134638, "id": 8833466, "is_goal": false, "is_important": false, "minute": 35, "order": 26 }, { "comment": "Bernardo Silva - Manchester City - won a free kick on the right wing.", "extra_minute": null, "fixture_id": 19134638, "id": 8833437, "is_goal": false, "is_important": false, "minute": 35, "order": 25 }, { "comment": "Shot blocked. Amad Diallo - Manchester United - shot with left foot from the right side of the box is blocked.", "extra_minute": null, "fixture_id": 19134638, "id": 8833436, "is_goal": false, "is_important": false, "minute": 35, "order": 24 }, { "comment": "Missed opportunity. Manuel Ugarte from Manchester United attempted a right-footed shot from outside the penalty area, but it sailed high and to the right of the goal. The assist came from Kobbie Mainoo.", "extra_minute": null, "fixture_id": 19134638, "id": 8833435, "is_goal": false, "is_important": false, "minute": 32, "order": 23 }, { "comment": "The attempt is deflected. Lisandro Martínez of Manchester United takes a left-footed shot from outside the penalty area, but it is blocked. The assist came from Manuel Ugarte.", "extra_minute": null, "fixture_id": 19134638, "id": 8833434, "is_goal": false, "is_important": false, "minute": 32, "order": 22 }, { "comment": "Harry Maguire from Manchester United has earned a free kick in the defensive area.", "extra_minute": null, "fixture_id": 19134638, "id": 8833416, "is_goal": false, "is_important": false, "minute": 29, "order": 21 }, { "comment": "Erling Haaland commits a foul for Manchester City.", "extra_minute": null, "fixture_id": 19134638, "id": 8833415, "is_goal": false, "is_important": false, "minute": 29, "order": 20 }, { "comment": "Offside call against Manchester United. Amad Diallo has been flagged for being offside.", "extra_minute": null, "fixture_id": 19134638, "id": 8833402, "is_goal": false, "is_important": false, "minute": 26, "order": 19 }, { "comment": "Missed chance. Rúben Dias - Manchester City - shot with the head from few metres goes high. Assist - Phil Foden with a cross after corner.", "extra_minute": null, "fixture_id": 19134638, "id": 8833377, "is_goal": false, "is_important": false, "minute": 23, "order": 18 }, { "comment": "Corner awarded to Manchester City after Harry Maguire gave it away.", "extra_minute": null, "fixture_id": 19134638, "id": 8833376, "is_goal": false, "is_important": false, "minute": 23, "order": 17 }, { "comment": "Shot blocked. Phil Foden - Manchester City - shot with left foot from the right side of the box is blocked. Assist - Erling Haaland.", "extra_minute": null, "fixture_id": 19134638, "id": 8833375, "is_goal": false, "is_important": false, "minute": 23, "order": 16 }, { "comment": "Missed chance. Phil Foden - Manchester City - shot with left foot from outside the box is close, but missed.", "extra_minute": null, "fixture_id": 19134638, "id": 8833358, "is_goal": false, "is_important": false, "minute": 21, "order": 15 }, { "comment": "Josko Gvardiol from Manchester City earned a free kick on the left side of the field.", "extra_minute": null, "fixture_id": 19134638, "id": 8833308, "is_goal": false, "is_important": false, "minute": 15, "order": 14 }, { "comment": "Noussair Mazraoui commits a foul against Manchester United.", "extra_minute": null, "fixture_id": 19134638, "id": 8833307, "is_goal": false, "is_important": false, "minute": 15, "order": 13 }, { "comment": "Substitution for Manchester United: Kobbie Mainoo comes on to replace Mason Mount due to an injury.", "extra_minute": null, "fixture_id": 19134638, "id": 8833306, "is_goal": false, "is_important": false, "minute": 14, "order": 12 }, { "comment": "The pause has ended. They’re set to resume play.", "extra_minute": null, "fixture_id": 19134638, "id": 8833305, "is_goal": false, "is_important": false, "minute": 14, "order": 11 }, { "comment": "Match is currently on hold due to an injury to Mason Mount from Manchester United.", "extra_minute": null, "fixture_id": 19134638, "id": 8833283, "is_goal": false, "is_important": false, "minute": 12, "order": 10 }, { "comment": "Offside call against Manchester United. Amad Diallo has been flagged for offside.", "extra_minute": null, "fixture_id": 19134638, "id": 8833268, "is_goal": false, "is_important": false, "minute": 11, "order": 9 }, { "comment": "Corner awarded to Manchester City after Lisandro Martínez allowed the ball to go out.", "extra_minute": null, "fixture_id": 19134638, "id": 8833233, "is_goal": false, "is_important": false, "minute": 5, "order": 8 }, { "comment": "Jérémy Doku from Manchester City has been awarded a free kick in the defensive area.", "extra_minute": null, "fixture_id": 19134638, "id": 8833232, "is_goal": false, "is_important": false, "minute": 4, "order": 7 }, { "comment": "Fouled by Manuel Ugarte - Manchester United. \n\nRephrased: Manuel Ugarte commits a foul against a Manchester United player.", "extra_minute": null, "fixture_id": 19134638, "id": 8833231, "is_goal": false, "is_important": false, "minute": 4, "order": 6 }, { "comment": "Matheus Nunes from Manchester City has been awarded a free kick on the left flank.", "extra_minute": null, "fixture_id": 19134638, "id": 8833242, "is_goal": false, "is_important": false, "minute": 3, "order": 5 }, { "comment": "Fouled by Rasmus Højlund - Manchester United", "extra_minute": null, "fixture_id": 19134638, "id": 8833220, "is_goal": false, "is_important": false, "minute": 3, "order": 4 }, { "comment": "Kevin De Bruyne of Manchester City has been awarded a free kick in the defensive area.", "extra_minute": null, "fixture_id": 19134638, "id": 8833210, "is_goal": false, "is_important": false, "minute": 2, "order": 3 }, { "comment": "Diogo Dalot from Manchester United committed a foul.", "extra_minute": null, "fixture_id": 19134638, "id": 8833209, "is_goal": false, "is_important": false, "minute": 2, "order": 2 }, { "comment": "The opening half is underway...", "extra_minute": null, "fixture_id": 19134638, "id": 8833208, "is_goal": false, "is_important": false, "minute": null, "order": 1 } ]
In the final chapter, we shall perform some advanced formatting to extract only the required data and present the commentaries in a refined way.
Let’s dive in.
Chapter 4. Retrieving Only Required Fields.
In this chapter, we will extract only the fields; minute and commentary. We will also remove minute fields with null values, leaving only the comment behind.
As you can see from the code section which serializes the sorted commentaries back to JSON was removed.
// Serialize the sorted list back to JSON let sorted_json = serde_json::to_string_pretty(&commentaries) .expect("Failed to serialize sorted commentaries to JSON");
Here’s the full code.
use reqwest::Error; use serde::{Deserialize, Serialize}; use serde_json::Value; #[derive(Debug, Deserialize, Serialize)] struct Commentary { comment: String, extra_minute: Option<i32>, fixture_id: i64, id: i64, is_goal: bool, is_important: bool, minute: Option<i32>, order: i32, } #[tokio::main] async fn main() -> Result<(), Error> { // Replace "API_Token" with your actual API token let api_token = "API_Token"; let url = format!( "https://api.sportmonks.com/v3/football/commentaries/fixtures/19134638?api_token={}", api_token ); // Send the GET request let response = reqwest::get(&url).await?; if response.status().is_success() { // Parse the JSON response let json: Value = response.json().await?; // Extract the "data" field which contains the list of commentaries if let Some(data) = json.get("data") { // Deserialize into a Vec<Commentary>, let mut commentaries: Vec<Commentary> = serde_json::from_value(data.clone()) .expect("Failed to deserialize 'data' field into Vec<Commentary>"); // Sort the commentaries by the "order" field in descending order commentaries.sort_by(|a, b| b.order.cmp(&a.order)); // Print each commentary, removing "null - " if the minute is missing for commentary in commentaries { if let Some(minute) = commentary.minute { println!("{} - {}", minute, commentary.comment); } else { println!("{}", commentary.comment); } println!(); // Add an empty line } } else { eprintln!("The 'data' field is missing in the response."); } } else { eprintln!("Failed to fetch data: {}", response.status()); } Ok(()) }
That's it! The match has concluded with Manchester City 1, Manchester United 2. 90 - The second half has concluded with the final score: Manchester City 1, Manchester United 2. 90 - Corner awarded to Manchester City after Victor Lindelöf allowed the ball to go out. 90 - Substitution for Manchester United: Victor Lindelöf comes on to replace Amad Diallo. 90 - The fourth official has indicated that there will be 5 minutes of stoppage time. 90 - Goal! Manchester City 1, Manchester United 2. Amad Diallo from Manchester United takes a left-footed shot from a challenging angle on the left side, sending the ball towards the center of the goal. The assist comes from Lisandro Martínez, who delivered a precise through ball. 89 - Substitution for Manchester City: Savinho is coming on to replace Ilkay Gündogan. 88 - Goal! Manchester City 1, Manchester United 1. Bruno Fernandes - Manchester United - converts the penalty with a shot with right foot to the right corner. 87 - The pause has ended. They are set to resume play. 86 - Delay in match - injury Amad Diallo - Manchester United 86 - Matheus Nunes from Manchester City has given away a penalty due to a foul committed inside the box. 86 - Penalty awarded to Manchester United! Amad Diallo is fouled inside the box. 84 - Corner awarded to Manchester City after Kobbie Mainoo allowed the ball to go out. 84 - Missed chance. Kobbie Mainoo - Manchester United - shot with the head from the centre of the box goes high. Assist - Lisandro Martínez with a cross. 79 - Substitution for Manchester United: Leny Yoro comes on to replace Matthijs de Ligt. 78 - Substitution for Manchester United: Antony replaces Noussair Mazraoui. 78 - Substitution for Manchester United: Joshua Zirkzee comes on to replace Rasmus Højlund. 78 - Opportunity squandered. Phil Foden of Manchester City takes a left-footed shot from outside the penalty area following a corner, but it sails over the goal. 77 - Substitution for Manchester City: Jack Grealish comes off, and Jérémy Doku takes his place. 76 - Corner awarded to Manchester City after Lisandro Martínez allowed the ball to go out. 76 - The attempt is denied. Erling Haaland from Manchester City fires a left-footed shot from the middle of the penalty area, but it's intercepted. The assist came from Mateo Kovacic. 74 - Missed chance. Bruno Fernandes - Manchester United - shot with right foot from the right side of the box is close, but missed to the left. Assist - Rasmus Højlund with a through ball following a fast break. 73 - Diogo Dalot of Manchester United committed a foul. 73 - Bernardo Silva from Manchester City has been awarded a free kick on the right flank. 72 - Offside call against Manchester United. Rasmus Højlund has been flagged for being in an offside position. 68 - Substitution for Manchester City: Mateo Kovacic is coming on to replace Kevin De Bruyne. 67 - Opportunity wasted. Kevin De Bruyne from Manchester City takes a left-footed shot from outside the penalty area, but it sails over the crossbar. 66 - Manuel Ugarte commits a foul against Manchester United. 66 - Bernardo Silva - Manchester City - won a free kick in attack. 62 - Corner awarded to Manchester United after Ederson allowed the ball to go out. 62 - Another offensive push from Manchester United. Amad Diallo heads the ball from the center of the box, but it's expertly saved in the right corner. The assist came from Bruno Fernandes, who delivered a precise cross. 58 - Fouled by Noussair Mazraoui of Manchester United. 58 - Matheus Nunes from Manchester City earned a free kick on the left flank. 58 - Kobbie Mainoo from Manchester United committed a foul. 54 - Matheus Nunes from Manchester City has been awarded a free kick in the defensive area. 54 - Diogo Dalot of Manchester United committed a foul. 53 - Corner kick awarded to Manchester City after Matthijs de Ligt allowed the ball to go out of play. 53 - Ilkay Gündogan from Manchester City committed a foul. 53 - Bruno Fernandes from Manchester United has earned a free kick in the defensive area. 51 - Diogo Dalot commits a foul for Manchester United. 51 - Bernardo Silva from Manchester City has been awarded a free kick in the defensive area. 50 - Manuel Ugarte commits a foul on a Manchester United player. 50 - Bernardo Silva from Manchester City has earned a free kick in the defensive zone. 50 - The attempt is thwarted. Amad Diallo of Manchester United takes a left-footed shot from outside the penalty area, but it gets blocked. The assist came from Bruno Fernandes. 47 - Offside call against Manchester United. Noussair Mazraoui has been caught offside. 45 - The second half is underway with the score at Manchester City 1, Manchester United 0. 45 - The first half has concluded with Manchester City leading Manchester United 1-0. 45 - Kevin De Bruyne from Manchester City has been awarded a free kick on the left flank. 45 - Lisandro Martínez from Manchester United committed a foul. 45 - Corner awarded to Manchester City after André Onana allowed the ball to go out. 45 - Another offensive push from Manchester City. Phil Foden takes a left-footed shot from outside the penalty area, but it's saved in the bottom left corner. The assist came from Ilkay Gündogan. 45 - Kevin De Bruyne from Manchester City has earned a free kick on the right side of the field. 45 - Fouled by Manuel Ugarte - Manchester United 45 - Fourth official has announced 4 minutes of added time. 45 - Manuel Ugarte - Manchester United - won a free kick in defence. 45 - Fouled by Erling Haaland - Manchester City 44 - Offside - Manchester United. Amad Diallo is in offside. 43 - Delay over. They are ready to continue. 43 - Delay in match - Manchester City 43 - New attacking attempt. Kevin De Bruyne - Manchester City - shot with right foot from long distance on the right is saved in the top right corner. 41 - Offside - Manchester United. Diogo Dalot is in offside. 40 - Corner - Manchester United. Conceded by Rúben Dias. 40 - Missed chance. Matthijs de Ligt - Manchester United - shot with the head from the centre of the box missed to the left. Assist - Bruno Fernandes . 40 - Kyle Walker from Manchester City has been shown a yellow card. 40 - Rasmus Højlund of Manchester United has been shown a yellow card. 38 - Rasmus Højlund from Manchester United earned a free kick in an offensive position. 38 - Kyle Walker from Manchester City committed a foul. 36 - Goal! Manchester City takes the lead with a score of 1-0 against Manchester United. Josko Gvardiol heads the ball into the center of the net from the middle of the box following a corner kick. 36 - Corner awarded to Manchester City after Noussair Mazraoui allowed the ball to go out of play. 36 - A shot is deflected! Jérémy Doku of Manchester City attempts a right-footed strike from the left side of the penalty area, but it's blocked. The assist came from Phil Foden. 35 - Bruno Fernandes from Manchester United committed a foul. 35 - Bernardo Silva - Manchester City - won a free kick on the right wing. 35 - Shot blocked. Amad Diallo - Manchester United - shot with left foot from the right side of the box is blocked. 32 - Missed opportunity. Manuel Ugarte from Manchester United attempted a right-footed shot from outside the penalty area, but it sailed high and to the right of the goal. The assist came from Kobbie Mainoo. 32 - The attempt is deflected. Lisandro Martínez of Manchester United takes a left-footed shot from outside the penalty area, but it is blocked. The assist came from Manuel Ugarte. 29 - Harry Maguire from Manchester United has earned a free kick in the defensive area. 29 - Erling Haaland commits a foul for Manchester City. 26 - Offside call against Manchester United. Amad Diallo has been flagged for being offside. 23 - Missed chance. Rúben Dias - Manchester City - shot with the head from few metres goes high. Assist - Phil Foden with a cross after corner. 23 - Corner awarded to Manchester City after Harry Maguire gave it away. 23 - Shot blocked. Phil Foden - Manchester City - shot with left foot from the right side of the box is blocked. Assist - Erling Haaland. 21 - Missed chance. Phil Foden - Manchester City - shot with left foot from outside the box is close, but missed. 15 - Josko Gvardiol from Manchester City earned a free kick on the left side of the field. 15 - Noussair Mazraoui commits a foul against Manchester United. 14 - Substitution for Manchester United: Kobbie Mainoo comes on to replace Mason Mount due to an injury. 14 - The pause has ended. They’re set to resume play. 12 - Match is currently on hold due to an injury to Mason Mount from Manchester United. 11 - Offside call against Manchester United. Amad Diallo has been flagged for offside. 5 - Corner awarded to Manchester City after Lisandro Martínez allowed the ball to go out. 4 - Jérémy Doku from Manchester City has been awarded a free kick in the defensive area. 4 - Fouled by Manuel Ugarte - Manchester United. Rephrased: Manuel Ugarte commits a foul against a Manchester United player. 3 - Matheus Nunes from Manchester City has been awarded a free kick on the left flank. 3 - Fouled by Rasmus Højlund - Manchester United 2 - Kevin De Bruyne of Manchester City has been awarded a free kick in the defensive area. 2 - Diogo Dalot from Manchester United committed a foul. The opening half is underway...
As you can see from the response, the ‘null -’ prefix is completely removed from comments where the minute’s value is missing.
CONCLUSION.
In the first chapter, we set up our environment and installed a platform-independent IDE named RustRover before heading off to obtain an API token for authentication.
We then moved to Chapter 2, where we retrieved all available commentaries from an endpoint. After making our content much more readable, we retrieved match commentaries from a specific fixture of interest using a fixture’s ID.
With little need to explain further, you can see that Rust is a modern and elegant programming language that has a gentle learning curve. No wonder it is the 14th most popular technology, according to a recent survey on Stack Overflow.
Are you up for the challenge? Perhaps you are building the next best thing and would like to work with Rust; we’ve got a boatload of endpoints, which includes topscorers, schedules, seasons, and livescores you could try it out with.
What are you waiting for? Sign up now!