Skip to content

Commit

Permalink
SQL Tutoorial
Browse files Browse the repository at this point in the history
  • Loading branch information
astechedu committed Apr 16, 2024
1 parent 50c6010 commit 585f8a0
Show file tree
Hide file tree
Showing 3 changed files with 246 additions and 0 deletions.
81 changes: 81 additions & 0 deletions sqlphp/developer-notes/js/javascript.http.request.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
>>> JavaScript(or Vanilla) Http Request <<<<<


--------------------------------------------------------------

Key:

----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------

In JavaScript, you can make HTTP requests using various tools and libraries. Some popular ones include:

1. XMLHttpRequest: This is a built-in object in web browsers that allows you to make HTTP requests from JavaScript. It has been around for a long time and provides basic functionality for making requests.

Example:

javascript

var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://api.example.com/data', true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
console.log(xhr.responseText);
}
};
xhr.send();



2. Fetch API: This is a modern alternative to XMLHttpRequest, providing a more powerful and flexible interface for fetching resources asynchronously across the network. It's available in most modern browsers.

Example:

javascript

fetch('https://api.example.com/data')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));




3. Axios: This is a popular Promise-based HTTP client for the browser and Node.js. It provides an easy-to-use API and handles common tasks like transforming request and response data.

Example:

javascript

axios.get('https://api.example.com/data')
.then(response => console.log(response.data))
.catch(error => console.error('Error:', error));





4. jQuery AJAX: If you're using jQuery, you can use its AJAX methods to make HTTP requests. However, with the advent of modern JavaScript and native APIs like Fetch, jQuery is becoming less necessary for simple AJAX requests.

Example:

javascript

$.ajax({
url: 'https://api.example.com/data',
method: 'GET',
success: function (data) {
console.log(data);
},
error: function (error) {
console.error('Error:', error);
}
});

These are just a few examples, and there are many other libraries and frameworks available for making HTTP requests in JavaScript, depending on your specific needs and preferences.


----------------------------------------------------------------
----------------------------------------------------------------
72 changes: 72 additions & 0 deletions sqlphp/developer-notes/php/php.http.request.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
>>> PHP Http Request <<<<<


--------------------------------------------------------------

Key:

----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------

In PHP, you have several options for making HTTP requests, both built-in functions and external libraries. Here are some commonly used methods:



1. cURL (Client URL Library): cURL is a widely used PHP library that allows you to make HTTP requests to URLs. It supports various protocols like HTTP, HTTPS, FTP, etc., and provides a rich set of options and functionalities.

Example:

php

$url = 'https://api.example.com/data';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;


2. file_get_contents(): This is a built-in PHP function that allows you to read the contents of a file into a string. When used with a URL, it can also be used to make HTTP requests and retrieve the response.

Example:


$url = 'https://api.example.com/data';
$response = file_get_contents($url);
echo $response;



3. fopen() and fread(): You can also use fopen() to open a connection to a URL and then use fread() to read the content of the response.

Example:

$url = 'https://api.example.com/data';
$handle = fopen($url, 'r');
$response = stream_get_contents($handle);
fclose($handle);
echo $response;


4. Guzzle HTTP Client: Guzzle is a popular PHP HTTP client that simplifies the process of sending HTTP requests and processing responses. It provides a more object-oriented and flexible way to work with HTTP requests compared to the built-in functions.

Example (assuming Guzzle is installed via Composer):

require 'vendor/autoload.php';

use GuzzleHttp\Client;

$client = new Client();
$response = $client->get('https://api.example.com/data');
echo $response->getBody();




These are some of the common methods for making HTTP requests in PHP. Depending on your requirements and preferences, you can choose the most suitable method for your project.


----------------------------------------------------------------
----------------------------------------------------------------
93 changes: 93 additions & 0 deletions sqlphp/developer-notes/python/python.http.request.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
>>> Python Http Request <<<<<


--------------------------------------------------------------

Key:

----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------

In Python, there are several libraries available for making HTTP requests. Here are some of the most commonly used ones:



1. Requests: Requests is one of the most popular HTTP libraries for Python. It provides a simple and elegant API that makes it easy to send HTTP requests and handle responses.

Example:


import requests

response = requests.get('https://api.example.com/data')
print(response.text)



2. urllib: This is a built-in module in Python that provides functions for working with URLs. While it's not as user-friendly as Requests, it's still a powerful tool for making HTTP requests.

Example:


from urllib import request

with request.urlopen('https://api.example.com/data') as response:
data = response.read()
print(data)




3. http.client: This is another built-in module in Python that allows you to make HTTP requests. It provides a lower-level interface compared to Requests and urllib, and it's generally used for more advanced use cases.

Example:


import http.client

conn = http.client.HTTPSConnection('api.example.com')
conn.request('GET', '/data')
response = conn.getresponse()
data = response.read()
print(data)





4. httplib2: This is a comprehensive HTTP client library for Python that provides support for features like caching, authentication, and more.

Example:


import httplib2

http = httplib2.Http()
response, content = http.request('https://api.example.com/data')
print(content)




5. aiohttp: If you're working with asynchronous code (e.g., in asyncio), aiohttp is a popular library for making asynchronous HTTP requests.

Example:


import aiohttp
import asyncio

async def fetch_data():
async with aiohttp.ClientSession() as session:
async with session.get('https://api.example.com/data') as response:
return await response.text()

data = asyncio.run(fetch_data())
print(data)

These are some of the most commonly used HTTP request libraries in Python. Depending on your project requirements and preferences, you can choose the one that best fits your needs.

----------------------------------------------------------------
----------------------------------------------------------------

0 comments on commit 585f8a0

Please sign in to comment.