I'm trying to pass some parameters with my API request so I can get data that's already filtered.
I'm using a module called Purest and it's basically a REST API client library. It supports making expressive query call as per Purest Query API
And, my API provider is Pocket and their documentation says the following more info here.
contentType
article = only return articles
video = only return videos or articles with embedded videos
image = only return images
sort
newest = return items in order of newest to oldest
oldest = return items in order of oldest to newest
title = return items in order of title alphabetically
site = return items in order of url alphabetically
Now, I want to get video data and sort it by newest. But I'm short on clues how to add these parameters in my query.
Below is what I've tried but I'm getting 400 Bad Request
. Not also sure what to put in select because I don't know the table name of this database.
var Purest = require('purest')
, getpocket = new Purest({provider:'getpocket'})
getpocket.query()
.select('')
.where({contentType:'video'},{sort:'newest'})
.post('get')
.auth('xxxxx', 'xxxxx')
.request(function (err, res, body) {
console.log(body);
})
Pocket's API accepts only POST requests, and expect you to send a JSON encoded request body:
With this provider specifically the Query API looks a bit weird, because the endpoint is called
get
and you are making aPOST
request to it.Purest is built on top of request and it's fully compatible with it. The following code will produce the exact same result as the above one:
Alternatively you can use request instead: