In the application and web services era, it is hard to ignore the importance of data transfer between online sources. Many web developers and programmers hit that roadblock in their time. but in WP ULike we developed a way to ease that pain. WP ULike now supports the Rest API for extracting data.
before getting deeper in configuration lets see how Rest API works.
What is the REST API?
An API is an application programming interface. It is a set of rules that allow programs to talk to each other. The developer creates the API on the server and allows the client to talk to it.
REST determines how the API looks like. It stands for “Representational State Transfer”. It is a set of rules that developers follow when they create their API. One of these rules states that you should be able to get a piece of data (called a resource) when you link to a specific URL.
Each URL is called a request while the data sent back to you is called a response.
The Anatomy Of A Request
It’s important to know that a request is made up of four things:
- The endpoint
- The method
- The headers
- The data (or body)
The endpoint (or route) is the URL you request for. It follows this structure:
root-endpoint/?
The root-endpoint is the starting point of the API you’re requesting from. The root-endpoint of Github’s API is https://api.github.com
while the root-endpoint Twitter’s API is https://api.twitter.com
.
The path determines the resource you’re requesting. Think of it like an automatic answering machine that asks you to press 1 for service, press 2 for another service, 3 for yet another service and so on.
How does REST API work on WP ULike?
Many of our users asked for a solution to extract and transfer data in JSON format. Therefore, we added Rest API compatibility to our plugin. you can access this feature from Setting> Developer Tools> Rest API.
As you can see, the integration is quite simple on this side. You need an Authentication method to transfer data. We use and recommend JWT Authentication for WP REST API. this plugin Extends the WP REST API using JSON Web Tokens Authentication as an authentication method.
JSON Web Tokens are an open, industry-standard RFC 7519 method for representing claims securely between two parties.
You can also use your own authentication solution with Custom Keys.
Also, you can easily manage who can have access to readable and writable roots in this section.
You can see an example of using Rest API to transfer data from WP ULike Log in the picture below:
Let’s talk about using the Endpoints
Get All Votes
Example Definition: GET http://yoursite.com/wp-json/wp-ulike-pro/v1/vote
Parameters:
- type: Select collection type between post, comment, activity & topic. (Default: post)
- page: Current page of the collection. (Default: 1)
- per_page: Maximum number of items to be returned in result set. (Default: 10)
- search: Limit results to those matching a string.
Create a New Vote
Example Definition: POST http://yoursite.com/wp-json/wp-ulike-pro/v1/vote
Parameters:
- item_id: Select item ID.
- user_id: Select user ID.
- type: Select collection type between post, comment, activity & topic.
- user_ip: Select user IP.
- status: Select voting status. (Like, Liked, Dislike, Disliked)
Update Vote Status
Example Definition: PUT http://yoursite.com/wp-json/wp-ulike-pro/v1/vote
Parameters:
- item_id: Select item ID.
- user_id: Select user ID.
- type: Select collection type between post, comment, activity & topic.
- status: Select voting status. (Like, Liked, Dislike, Disliked)
Get Single Vote
Example Definition: Get http://yoursite.com/wp-json/wp-ulike-pro/v1/vote/1
Parameters:
- id: Select vote ID.
- type: Select collection type between post, comment, activity & topic. (Default: post)
Update Single Vote
Example Definition: PUT http://yoursite.com/wp-json/wp-ulike-pro/v1/vote/1
Parameters:
- id: Select vote ID.
- item_id: Select item ID.
- user_id: Select user ID.
- type: Select collection type between post, comment, activity & topic.
- status: Select voting status. (Like, Liked, Dislike, Disliked)
Get Top Users List
Example Definition: GET http://yoursite.com/wp-json/wp-ulike-pro/v1/user
Parameters:
- type: Select collection type between post, comment, activity & topic. (Default: post)
- page: Current page of the collection. (Default: 1)
- per_page: Maximum number of items to be returned in result set. (Default: 10)
- order: Select order type between DESC, ASC (Default: DESC)
- status: Select voting status. (Like, Liked, Dislike, Disliked)
-
period: Select date range period. (Default: all)
Get User Data
Example Definition: GET http://yoursite.com/wp-json/wp-ulike-pro/v1/user/1
Parameters:
- id: Select user ID.
- type: Select collection type between post, comment, activity & topic. (Default: post)
- page: Current page of the collection. (Default: 1)
- per_page: Maximum number of items to be returned in result set. (Default: 10)
- order: Select order type between DESC, ASC (Default: DESC)
- status: Select voting status. (Like, Liked, Dislike, Disliked)
-
period: Select date range period. (Default: all)
Get Statistics Data
Example Definition: GET http://yoursite.com/wp-json/wp-ulike-pro/v1/stats
Parameters:
- dataset: Select the type of data from the following options:
- count_all_logs_all
- count_all_logs_today
- count_all_logs_yesterday
- get_top_likers
- dataset_ulike
- get_top_posts
- count_logs_ulike_week
- count_logs_ulike_month
- count_logs_ulike_year
- count_logs_ulike_all
- dataset_ulike_comments
- get_top_comments
- count_logs_ulike_comments_week
- count_logs_ulike_comments_month
- count_logs_ulike_comments_year
- count_logs_ulike_comments_all
- dataset_ulike_activities
- get_top_activities
- count_logs_ulike_activities_week
- count_logs_ulike_activities_month
- count_logs_ulike_activities_year
- count_logs_ulike_activities_all
- dataset_ulike_forums
- get_top_topics
- count_logs_ulike_forums_week
- count_logs_ulike_forums_month
- count_logs_ulike_forums_year
- count_logs_ulike_forums_all
- start_date: Select start date. (Format: Y-m-d)
- end_date: Select end date. (Format: Y-m-d)
- status: Select voting status. (like, dislike, unlike, undislike)
-
filter: Select post types filter. (separate items by comma)
We need Your help!
Despite our best efforts, there will be bugs or issues with WP ULike Root for REST. so, please report these problems via Support Service.
On the other hand, there is always room for improvement for us and we will appreciate any suggestions and ideas to make our product better.