Connect to a Server

Learn how to connect to a REST server using the Requests library.

REST follows the client-server model. The server provides endpoints to connect to and serves data as per the request. The client connects to the endpoint and requests data. The request and response always follow the HTTP request-response model. For simplicity, in place of the API endpoint, the term “service” will be used.

The task of connecting to a server can be divided into two types:

  • Without configuration
  • With configuration

This distinction occurs due to a variety of reasons, including but not limited to, authentication mechanisms used by the server and the certificate type of the server. In this lesson, we’ll look at how to connect to a server without the client needing to configure itself. For completeness, the client will try to fetch data, i.e., issue a GET. We’ll be connecting to the air quality service provided by MET Norway. The URI is as follows:

https://api.met.no/weatherapi/airqualityforecast/0.1/stations.

Previously, we had chosen the requests library to use for our client. Let’s see how to use our chosen library to connect to the service.

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy