RESTful Web Services

Latar Belakang Web Services (Programmable Web) Website yang kita buat tentu kita desain agar  manusia dapat dengan mudah dan nyaman untuk mengakses informasi yang ada didalamnya. Namun,  bagaimana jika yang mengakses website kita adalah sebuah program komputer? Sudah menjadi rahasia umum, jika programmer sering menggunakan cara tidak resmi untuk mendapatkan informasi yang ada dalam sebuah website  dengan teknik screen-scraping misalnya. Namun sayang, program komputer tidak se-fleksibel manusia dalam hal menafsirkan data yang ada dalam sebuah website. Maka, muncullah teknologi seperti RSS, XML-RPC, SOAP, RESTful Web Services, dll. Teknologi-teknologi tersebut dibuat untuk membuat website kita lebih mudah dibaca atau ditafsirkan oleh program komputer. Apa Itu RESTful Web Services? RESTful Web Services mengacu pada sebuah cara atau gaya dalam membangun sebuah sistem web services dengan memanfaatkan semua fitur/potensi yang dimiliki oleh teknologi HTTP (Hypertext...

Google News Feed API Alternative


As a web developer, I used Google News Feed API for converting RSS Feed to JSON format. I like more JSON than XML format, because it's easy to parse from my programming languages (Javascript or PHP or Python). Since google announced that they had deprecated this service, I was looking for new service that has ability like Google News Feed API. I opened google.com and type "Google News Feed API Alternative" and I found YQL (Yahoo! Query Language).

YQL has ability to access RSS Feed data with SQL-like commands and parse the result to JSON format. For example, I'll show you how to get feed data from Yahoo! News Top Stories (http://rss.news.yahoo.com/rss/topstories)  using jQuery ajax function.

See the Pen Yahoo! Query Language (jQuery) by Yuda Sukmana (@ydatech) on CodePen.


According to the example above, these are some important things to use YQL on your project :

1. YQL API URL/Endpoint
We have to send a GET request to https://query.yahooapis.com/v1/public/yql

var yql  = 'https://query.yahooapis.com/v1/public/yql'

I'm storing YQL API endpoint in yql Javascript variable

2. Query
We have to write this query to get feed data from a RSS Feed and send it through q parameter while we send the GET request :

var query = 'select * from rss where url="http://rss.news.yahoo.com/rss/topstories"'


In this case, I'm storing the query in Javascript query variable. you can learn more about YQL queries/commands on this page :  https://developer.yahoo.com/yql/guide


3. Response Format
To get JSON format, just send format parameter with "json" value while you send the GET request. You can also get XML format by changing format parameter value by "xml".

4. Send GET request with jQuery
This is jQuery code to send our query to YQL endpoint..

$.get(yql, { q : query , format : 'json' } , function(response){ console.log(response)})

5.  Other YQL Parameters
The following table lists will show you other YQL parameters that you can use while send a GET request to YQL endpoint.

6. YQL console
Try to write your query and get the result instantly on YQL console page : https://developer.yahoo.com/yql/console/

Finally, I hope that you found the Google News Feed API alternative on this post.

See Ya...

Comments



Popular posts from this blog

Membuat Model Menggunakan Fitur Gii Console Command di Yii2

Implementasi Rancangan Database menggunakan fitur Database Migration di Yii2