Читать книгу Английский для программистов. Как общаться в международных IT-командах - - Страница 8

Working with APIs (Работа с API)

Оглавление

В последние годы работа с API стала важной частью разработки, и Ирина, опытный разработчик, делится своими знаниями с коллегой Александром.


Сегодня Ирина и Александр работают над проектом, который использует сторонний API для получения данных о погоде. Они решают, как правильно отправить запросы к API и обработать полученные ответы.


Диалог на встрече:


Irina:

«Hey, Alexander! We need to integrate the weather API into our app. Have you worked with APIs before?»


Alexander:

«Yes, I have some experience, but I’m not sure how to handle authentication for this one. Do we need an API key?»


Irina:

«Yes, you’ll need to sign up on the website to get an API key. After that, you’ll use it in the request headers for authentication.»


Alexander:

«Got it! So, how do we send a request to the API?»


Irina:

«You can use a GET request to get weather data. The endpoint is something like /weather, and you’ll need to pass the city name as a parameter in the URL.»


Alexander:

«Sounds good. What about handling the response? Should I check if the response status code is 200?»


Irina:

«Exactly! A 200 OK status means the request was successful. After that, you can parse the JSON response and extract the data you need.»


Alexander:

«Okay, I’ll write the code to send the request and handle the response. Thanks for the help!»


Irina:

«No problem, let me know if you run into any issues.»

Полезные фразы и выражения

API key – ключ API.


Authentication – аутентификация.


Request headers – заголовки запроса.


Send a request – отправить запрос.


GET request – запрос типа GET.


Endpoint – конечная точка (URL, к которому обращаются).


Parameter – параметр запроса.


Status code – код состояния ответа.


200 OK – код успешного выполнения запроса.


Parse the response – обработать (распарсить) ответ.


JSON response – ответ в формате JSON.

Упражнения

1. Vocabulary Match:


Соедините английские фразы с их русскими эквивалентами:


API key


Authentication


Send a request


GET request


Parse the response


a) Отправить запрос

b) Аутентификация

c) Запрос типа GET

d) Обработать (распарсить) ответ

e) Ключ API


2. Fill in the blanks:


Заполните пропуски подходящими словами из списка:


«You’ll need an ______ to authenticate your requests to the API.»


«We can send a ______ to get data from the weather API.»


«Make sure to check the ______ to see if the request was successful.»


«The API returns a ______ response, which we can use to get the weather data.»


(Answers: API key, GET request, status code, JSON)


3. Translate the following sentences into English:


Для отправки запроса к API, вам нужно будет указать ключ API в заголовке.


Я проверю код состояния ответа и, если он будет равен 200, начну обработку данных.


Ответ от API приходит в формате JSON, который легко распарсить.


4. Conversation Practice:


Практикуйте диалог с партнером или самостоятельно, используя фразы из главы. Один из вас будет играть роль Ирины, а другой – Александра. Пример:


Person 1 (Irina): «Alexander, have you added the API key to the request headers?»


Person 2 (Alexander): «Yes, I’ve added it. Now I’ll send the GET request to get the weather data.»


Самопроверка:


Which of the following phrases means «to send a request to get data from an API»?


a) Parse the response


b) Send a request


c) Check the status code


What does a 200 OK status code indicate?


a) The request was successful


b) The API key is invalid


c) The server is down


Choose the correct sentence in English:


a) «I will parse the response and extract the weather data from it.»


b) «I will parsed the response and extract the weather data from it.»

Ответы

1. Vocabulary Match:

1 – e

2 – b

3 – a

4 – c

5 – d


2. Fill in the blanks:


«You’ll need an API key to authenticate your requests to the API.»


«We can send a GET request to get data from the weather API.»


«Make sure to check the status code to see if the request was successful.»


«The API returns a JSON response, which we can use to get the weather data.»


3. Translate the sentences:


To send a request to the API, you’ll need to include the API key in the headers.


I’ll check the status code, and if it’s 200, I’ll start processing the data.


The response from the API comes in JSON format, which is easy to parse.


4. Self-Check:


b) Send a request


a) The request was successful


a) «I will parse the response and extract the weather data from it.»

Английский для программистов. Как общаться в международных IT-командах

Подняться наверх