Conteúdo do Curso
Introduction to .NET with C#
Introduction to .NET with C#
2. Asynchronous Programming and Introduction to Web Services
3. Introduction to Databases with .NET
Task - Using an API
There is a free public API, it is called Numbers API. It has multiple endpoints, one of which returns a random fact about any date of the year.
The base code is given. The program takes a month number and a day number from the user.
Task: Make a request to the Numbers API to retrieve a random fact about that date.
Guidelines:
The format of retrieving a fact about some date is: http://numbersapi.com/<month>/<day>/date
where <month>
represents the number of the month and <day>
represents the number of the day. For example, if the user enters 11
for the month (which represents the 11th month - November) and 6
for the day, the URL will be: http://numbersapi.com/11/6/date
Steps:
- Create a new variable called
url
and store the URL following the format explained in the Guidelines. You might need to use string formatting; - Create a new
HttpClient()
object; - Use the
HttpClient
object and make aGET
request to theurl
; - Store the response of the HTTP request into a
HttpResponseMessage
object; - Extract the raw message text from the
HttpResponseMessage
object usingReadAsStringAsync
method; - Display the message.
Note
This task does not have unit tests. You can verify the correctness of your code based on a successful response from the API.
Tudo estava claro?