• Non ci sono risultati.

mashup, cURL jQuery, REST,

N/A
N/A
Protected

Academic year: 2021

Condividi "mashup, cURL jQuery, REST,"

Copied!
21
0
0

Testo completo

(1)

jQuery, REST, mashup, cURL

(cenni)

(2)

2

JavaScript framework

Esistono dei framework di sviluppo per evitare di

“reinventare la ruota”

Esempi di framework

jQuery

Bootstrap

Angular.js

Node.js

Inoltre, questi framework risolvono problemi

cross-platform e supportano diversi browsers

(3)

3

jQuery

È una libreria JavaScript

Semplifica lo scripting client-side

È free e open source

È rilasciata sotto licenza MIT e GPL v.2

(4)

4

jQuery: ne fanno uso

Google

Dell

Major League Baseball

Bank of America

Drupal.org

Digg

Wordpress

NBC

e altri ancora ...

(5)

5

jQuery: installazione

Download the jQuery library from jQuery.com

<head>

<script src="jquery-1.12.2.min.js"></script>

</head>

Include jQuery from a CDN, like Google

<head>

<script

src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"

>

</script>

</head>

(6)

6

jQuery: sintassi

La sintassi di jQuery permette di selezionare

elementi HTML e di eseguire azioni su di essi

$(selector).action()

$ per definire/accedere a jQuery

(selector) per selezionare gli elementi HTML

action() per specificare l'azione da svolgere

Si può agire solo su elementi HTML già caricati nella pagina corrente Vedi: http://www.w3schools.com/jquery/jquery_syntax.asp

(7)

7

jQuery: selettori

Vedi: http://www.w3schools.com/jquery/jquery_selectors.asp

(8)

8

jQuery: eventi

In jQuery, la maggior parte degli eventi del DOM hanno un metodo jQuery equivalente

Eventi DOM

(9)

9

jQuery: eventi

In jQuery, la maggior parte degli eventi del DOM hanno un metodo jQuery equivalente

Metodi jQuery

(10)

10

Document Ready Event

Spesso i metodi jQuery sono all'interno dell'evento ready per evitare al codice jQuery di essere essere eseguito prima del caricamento del documento

$(document).ready(function(){

// metodi jQuery qui...

})

(11)

11

$.ajax() Function

La funzione $.ajax() permette di fare chiamate HTTP asincrone (http://api.jquery.com/jquery.ajax/)

$.ajax(url [, options] )

$.ajax([options])

url: indirizzo della chiamata

success: funzione da invocare se la richiesta va a buon fine

error: funzione da invocare se fallisce la richiesta

type: GET o POST

data: dati da inviare come parametro della richiesta

(12)

13

REST

Con Representational State Transfer (REST) si intende un tipo di architettura software per i sistemi distribuiti

Il termine è stato introdotto nel 2000 nella tesi di dottorato di Roy Fielding, uno dei principali autori delle specifiche del protocollo HTTP

http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm

(13)

14

REST

“...The World Wide Web represents the largest implementation of a system conforming to the REST architectural style.

REST-style architectures conventionally consist of clients and servers. Clients initiate requests to servers; servers process requests and return

appropriate responses. Requests and responses

are built around the transfer of representations of

resources.”

(14)

15

REST

I servizi vengono invocati usando i metodi del protocollo HTTP

Generalmente i risultati sono restituiti in XML o JSON

Il parsing dei risultati può essere fatto lato

client (con Ajax e JavaScript) oppure lato

server

(15)

16

REST

(16)

17

Mashup

L'uso di API REST permette di realizzare dei mashup

“... A mashup, in web development, is a web page, or web application, that uses and combines data, presentation or functionality from two or more sources to create new

services. The term implies easy, fast integration,

frequently using open application programming interfaces (API) and data sources to produce enriched results that were not necessarily the original reason for producing the raw source data.”

Fonte: http://en.wikipedia.org/wiki/Mashup_web_application_hybrid

(17)

18

Mashup lato server e lato client

(18)

19

Esempio di mashup lato client

Uso di geolocation HTML5

API di GoogleMaps

API REST di openWeatherMap

http://openweathermap.org/

(19)

20

Mashup lato server

I programmi sul server devono invocare servizi remoti, ricevere i dati e trasformarli in HTML per il client

La comunicazione server-to-server in PHP si può ottenere usando le librerie per cURL

“PHP supports libcurl, a library created by Daniel Stenberg, that allows you to connect and communicate to many different types of servers with many different types of protocols. libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols. libcurl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP

uploading (this can also be done with PHP's ftp extension), HTTP form based upload,” proxies, cookies, and user+password

(20)

21

Scenario cURL

Richiesta HTTP Risposta HTTP

web server 1

web server 2 cURL permette di

recuperare il contenuto di una pagina web (scraping)

effettuare il submit di un form effettuare autenticazioni

connettersi a servizi remoti

(21)

22

Scenario cURL

curl_init()

inizializza una sessione cURL

curl_setopt()

specifica le opzioni per la sessione

curl_exec()

esegue la chiamata vera e propria

curl_close()

chiude la sessione e rilascia le risorse

Riferimenti

Documenti correlati

Although, Cap43 has no cysteine or histidine-rich motifs for metal binding, it has a mono-histidine fragment, 10 amino acids (Thr–Arg–Ser–Arg–Ser–His–Thr–Ser–Glu–

Un primo punto è che non si tratti di un traduttore ambizioso o dalle larghe vedute; tradurre, dopotutto, non era nemmeno il suo pane quotidiano (in tempi normali infatti

This project is intended to contribute to the ongoing research on paper degradation. The main purpose of the present work is to shed some light on the

Available Open Access on Cadmus, European University Institute Research Repository... For contacts with the British Authorities see the minutes of a meeting of CIR

L’interfaccia remota del client prevede un singolo metodo, remoteEvent, che il server chiama per inviare una notifica al client, tipicamente al fine di comunicare che è avvenuto

elements on a page – one element or a group elements on a page – one element or a group. of them

Il mercato del lavoro (IV trimestre 2020) Istat Statistiche Flash, 12 marzo 2021. Andamento dell’economia italiana