-- Practice Final Thread
Group 9 Question 9
Kate Kazantseva, Nhien Lam
a) JSONP
JSONP stands for JSON with Padding. It returns a JS function with JSON data in it. The purpose of JSONP is to do proxying from client side by using the script tag.
Example from lectures:
This request
https://www.yioop.com/s/news?f=json&callback=myHandleDataCode
returns data that looks like:
myHandleDataCode({"language":"en-US","link":"http...etc...etc ...});
b) Proxy
Proxy allows us to to make requests to other servers.
Example from lectures:
<?php
define ('YIOOP_NEWS_URL', 'https://www.yioop.com/s/news/');
// look at incoming request fields
$query = (!empty($_REQUEST['f']) && in_array($_REQUEST['f'], ["rss", "json"])) ?
"?f=" . $_REQUEST['f'] : "";
$url = YIOOP_NEWS_URL . $query;
// Open the Curl session
$request_handle = curl_init($url);
// Don't bother with the HTTP headers. Do bother with the content back
curl_setopt($request_handle, CURLOPT_HEADER, false);
curl_setopt($request_handle, CURLOPT_RETURNTRANSFER, true);
// Make proxy request
$response_content = curl_exec($request_handle);
//determine the content-type of the response
$pre_content_type = curl_getinfo($request_handle, CURLINFO_CONTENT_TYPE);
$content_type = (empty($pre_content_type)) ? "text/html" : $pre_content_type;
// Set the outgoing proxy content type
header("Content-Type: $content_type");
echo $response_content;
curl_close($request_handle);
(c) REST (Representational State Transfer) - The idea of REST is that an application state or method is viewed as a resource. Each resource has a URL and one way to tack on to this URL a query to invoke the function and return results.
An example from the lecture slides, the Yioop News Service might be invoked with a line like:
http://www.yioop.com/s/news?f=rss&limit=20&num=30
, where "http://www.yioop.com/s/news" is the resource and “f”, “limit”, and “num” are the arguments which control the returned value from the resource.
(d) C10K problem
C10K is a problem when servers have over 10,000 simultaneous open connections and a limited thread pool. They are unable to handle all incoming requests and it will slow the servers down once these limits have been exhausted.
For example, a server handles a large number of clients at the same time.
(
Edited: 2021-05-17)
'''Group 9 Question 9'''
Kate Kazantseva, Nhien Lam
'''a) JSONP'''
JSONP stands for JSON with Padding. It returns a JS function with JSON data in it. The purpose of JSONP is to do proxying from client side by using the script tag.
Example from lectures:
This request
https://www.yioop.com/s/news?f=json&callback=myHandleDataCode
returns data that looks like:
myHandleDataCode({"language":"en-US","link":"http...etc...etc ...});
'''b) Proxy'''
Proxy allows us to to make requests to other servers.
Example from lectures:
<?php
define ('YIOOP_NEWS_URL', 'https://www.yioop.com/s/news/');
// look at incoming request fields
$query = (!empty($_REQUEST['f']) && in_array($_REQUEST['f'], ["rss", "json"])) ?
"?f=" . $_REQUEST['f'] : "";
$url = YIOOP_NEWS_URL . $query;
// Open the Curl session
$request_handle = curl_init($url);
// Don't bother with the HTTP headers. Do bother with the content back
curl_setopt($request_handle, CURLOPT_HEADER, false);
curl_setopt($request_handle, CURLOPT_RETURNTRANSFER, true);
// Make proxy request
$response_content = curl_exec($request_handle);
//determine the content-type of the response
$pre_content_type = curl_getinfo($request_handle, CURLINFO_CONTENT_TYPE);
$content_type = (empty($pre_content_type)) ? "text/html" : $pre_content_type;
// Set the outgoing proxy content type
header("Content-Type: $content_type");
echo $response_content;
curl_close($request_handle);
'''(c) REST''' (Representational State Transfer) - The idea of REST is that an application state or method is viewed as a resource. Each resource has a URL and one way to tack on to this URL a query to invoke the function and return results.
An example from the lecture slides, the Yioop News Service might be invoked with a line like:
http://www.yioop.com/s/news?f=rss&limit=20&num=30
, where "http://www.yioop.com/s/news" is the resource and “f”, “limit”, and “num” are the arguments which control the returned value from the resource.
'''(d) C10K problem'''
C10K is a problem when servers have over 10,000 simultaneous open connections and a limited thread pool. They are unable to handle all incoming requests and it will slow the servers down once these limits have been exhausted.
For example, a server handles a large number of clients at the same time.