Request of HTTP requests

Parameters in a request

Lesson Details:
June 29, 2020


I: Introduction

The web application development (WAD) is a special domain of computer programming. Being such a broad term, it can be applied to many different fields of software development like:

Web Applications

Mobile Applications

Desktop Applications

Web Service Development

Cloud Computing

Because of this wide range, we use the term Web Development and we will be using it throughout our article. Besides that, we will also cover all other topics relevant to Web Development. Our goal is to give an overview about the WAD as a whole and outline the fact that it is a broad field.

A: Cloud computing for machine learning

Machine Learning (ML) is a field of computer science that uses statistical techniques to give computers the ability to “learn” with data, without being explicitly programmed.

One of the biggest problems in ML is computing resources because we need a lot of processing power to train and run ML models. The reason for that is that ML is very computationally intensive and requires many iterations (or loops) through the data to learn what we want to learn.

To be able to train and run ML models, we need very powerful machines and because those don’t come cheap, we need to think about alternatives. One such alternative is cloud computing. Cloud computing refers to the delivery of hosted services through a computer network like the internet. Cloud computing allows us, as developers, to have access to a lot of computing resources at a very low cost compared to having our own machines.

There are several advantages of using cloud computing for ML:

Scalability – With cloud computing you can scale your infrastructure up or down based on your needs. When you need more resources you can simply use more machines from the cloud infrastructure provider. And when you don’t need those resources anymore you can scale those machines back down or terminate those instances so you only pay for the resources you need.

Use as-a-service – In cloud computing, you can use your infrastructure as a service so you don’t have to worry about maintaining them yourself. You can focus on training and running your models instead of worrying about backups, security, disk space, etc. Because of this fact, cloud computing can be a very cost-effective solution for ML projects.

Lower hardware costs – Using your own hardware to train or run your models is expensive because you have to buy very expensive hardware to make sure you have enough power to train and run those complex models. With cloud computing, you share these costs with other customers which makes it much more affordable for companies with smaller budgets.

II: Body

In this section we describe the parameters in a request using Python Requests library for Python 3.6. To do so, we will use the following example URL: https://translate.googleapis.com/language/translate?sl=en&tl=fr&text=Hello world!&key=my_api_key . It takes some parameters like text, language and key. We will describe each parameter below:

text – This is the text that we want to translate into another language. It can be either encoded or unencoded text. Encoded text means that the text contains some special characters that need translation (like for spaces). If you try to send encoded text without specifying how it should be encoded, Google will encode it for you automatically. Unencoded text means that the texts contains no special characters and is already encoded (for example UTF-8). You can specify if your text is encoded or not by adding an &encoding= parameter (see next parameter). For more information on specifying encoding see this documentation page of Google Translate API . There are some exceptions for this rule though. An example would be the case where the Unicode of the text is invalid or not supported by the language requested; in that case, an exception will be thrown by Google’s servers rather than attempting to decode the text anyway.

– This is the text that we want to translate into another language. It can be either encoded or unencoded text. Encoded text means that the text contains some special characters that need translation (like for spaces). If you try to send encoded text without specifying how it should be encoded, Google will encode it for you automatically. Unencoded text means that the texts contains no special characters and is already encoded (for example UTF-8). You can specify if your text is encoded or not by adding an parameter (see next parameter). For more information on specifying encoding see this documentation page of . There are some exceptions for this rule though. An example would be the case where the Unicode of the text is invalid or not supported by the language requested; in that case, an exception will be thrown by Google’s servers rather than attempting to decode the text anyway. encoding – This parameter is optional but if you include it then you must set its value equal to ISO-8859-1 , UTF-8 , UTF-16 , UTF-32 , US-ASCII , or Big5 . The reason why this parameter is optional is because Google will try to detect the encoding of your string automatically if you don’t specify it (if your string was sent using ISO-8859-1 , UTF-8 , UTF-16 , UTF-32 , US-ASCII , or Big5 ). Here is how Google does it: If there are no characters in any other encoding except US-ASCII , then the string will be decoded using your system’s default character encoding. If there are characters in multiple encodings except US-ASCII , then the string will be decoded using UTF-8 (if there aren’t any bytes greater than 128). If there are bytes greater than 128 but no characters in any other encoding except US-ASCII , then all non-ASCII bytes will be replaced with ‘?’. If there are characters in multiple encodings except US-ASCII , then the string will be decoded using UTF-16 (if there aren’t any surrogate pairs). If there are surrogate pairs but no characters in any other encoding except US-ASCII , then all non-ASCII surrogates will be replaced with ‘?’ and all non-ASCII high bytes will be replaced with ‘?’. If there are characters in multiple encodings except US-ASCII , then it will throw an exception instead of trying to decode your string using one specific encoding. In short, this parameter should only be used when you know exactly what it does because otherwise Google may throw an exception when trying to decode your text if it contains characters from multiple encodings in a single string. However, it might still be useful in cases where you want to handle multiple encodings manually in a single string because Google Translate API will always assume UTF-8 when it doesn’t find any other bidirectional symbols in a string. Note: Before version 3 of Google Translate API , if charset parameter was specified, encoding would use charset instead of detecting character encoding automatically from HTTP headers or query parameters. In version 3+, charset parameter is ignored and encoding will be detected automatically from HTTP headers or query parameters if present . It is recommended to remove charset from your requests going forward since encoding takes precedence over charset .

– This parameter is optional but if you include it then you must set its value equal to , , , , or . The reason why this parameter is optional is because Google will try to detect the encoding of your string automatically if you don’t specify it (if your string was sent using , , , , or ). Here is how Google does it: If there are no characters in any other encoding except , then the string will be decoded using your system’s default character encoding. If there are characters in multiple encodings except , then the string will be decoded using (if there aren’t any bytes greater than 128). If there are bytes greater than 128 but no characters in any other encoding except , then all non-ASCII bytes will be replaced with ‘?’. If there are characters in multiple encodings except , then the string will be decoded using (if there aren’t any surrogate pairs). If there are surrogate pairs but no characters in any other encoding except , then all non-ASCII surrogates will be replaced with ‘?’ and all non-ASCII high bytes will be replaced with ‘?’. If there are characters in multiple encodings except , then it will throw an exception instead of trying to decode your string using one specific encoding

loader
Course content