Cross-orgin requests with JSONP
JSONP is a method for sending JSON data without worrying about cross-domain issues. This is sometimes needed when calling third-party APIs that don't come with appropriate CORS settings.
import jsonp from 'superagent-jsonp';
import { Resource } from 'rest-hooks';
export default class ArticleResource extends Resource {
readonly id: number | undefined = undefined;
readonly content: string = '';
pk() {
return this.id;
}
static urlRoot = 'http://test.com/article/';
// OPERATIVE LINE HERE
static fetchPlugin = jsonp;
}
Using the jsonp plugin for superagent makes this quite easy.