-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📜Implemented the fetching data from an external API
- Loading branch information
1 parent
3b52ad3
commit d000063
Showing
4 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace StarWarsPlanetStatus.DTOs; | ||
|
||
public record Result( | ||
[property: JsonPropertyName("name")] string name, | ||
[property: JsonPropertyName("rotation_period")] string rotation_period, | ||
[property: JsonPropertyName("orbital_period")] string orbital_period, | ||
[property: JsonPropertyName("diameter")] string diameter, | ||
[property: JsonPropertyName("climate")] string climate, | ||
[property: JsonPropertyName("gravity")] string gravity, | ||
[property: JsonPropertyName("terrain")] string terrain, | ||
[property: JsonPropertyName("surface_water")] string surface_water, | ||
[property: JsonPropertyName("population")] string population, | ||
[property: JsonPropertyName("residents")] IReadOnlyList<string> residents, | ||
[property: JsonPropertyName("films")] IReadOnlyList<string> films, | ||
[property: JsonPropertyName("created")] DateTime created, | ||
[property: JsonPropertyName("edited")] DateTime edited, | ||
[property: JsonPropertyName("url")] string url | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace StarWarsPlanetStatus.DTOs; | ||
|
||
public record Root( | ||
[property: JsonPropertyName("count")] int count, | ||
[property: JsonPropertyName("next")] string next, | ||
[property: JsonPropertyName("previous")] object previous, | ||
[property: JsonPropertyName("results")] IReadOnlyList<Result> results | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
using System.Text.Json; | ||
using StarWarsPlanetsStats.ApiDataAccess; | ||
using StarWarsPlanetStatus.DTOs; | ||
|
||
var apiDataReader = new ApiDataReader(); | ||
|
||
var json = await apiDataReader.Read("https://swapi.dev/", "api/planets"); | ||
|
||
var root = JsonSerializer.Deserialize<Root>(json); | ||
|
||
Console.ReadKey(); | ||
Console.WriteLine("Hello, World!"); |