How to use the wpapi.discover function in wpapi

To help you get started, we’ve selected a few wpapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / wpapi / wpapi-tests.ts View on Github external
/* ... */
        }
    );

    // Namespaces can be saved out to variables:
    const myplugin = site.namespace("myplugin/v1");
    myplugin
        .authors()
        .id(7)
        .then((author: any) => {
            /* ... */
        });
});

// Authenticating with Auto-Discovery
const apiPromise2 = WPAPI.discover("http://my-site.com").then(site => {
    return site.auth({
        username: "admin",
        password: "always use secure passwords"
    });
});

apiPromise2.then(site => {
    // site is now configured to use authentication
});

// You must authenticate to be able to POST (create) a post
const wp2 = new WPAPI({
    endpoint: "http://your-site.com/wp-json",
    // This assumes you are using basic auth, as described further below
    username: "someusername",
    password: "password"
github DefinitelyTyped / DefinitelyTyped / types / wpapi / wpapi-tests.ts View on Github external
}
    // do something with the returned posts
});

// Promises
wp
    .posts()
    .then((data: any) => {
        // do something with the returned posts
    })
    .catch((err: Error) => {
        // handle error
    });

// Auto-discover
const apiPromise = WPAPI.discover("http://my-site.com");
apiPromise.then(site => {
    // If default routes were detected, they are now available
    site.posts().then((posts: any[]) => {}); // etc

    // If custom routes were detected, they can be accessed via .namespace()
    // Custom routes have different methods to generate requests, so .authors()
    // does not necessarily exist. You have use force type  or 'as
    // Request'
    (site.namespace("myplugin/v1").authors() as WPAPI.WPRequest).then(
        (authors: any[]) => {
            /* ... */
        }
    );

    // Namespaces can be saved out to variables:
    const myplugin = site.namespace("myplugin/v1");
github bitterendio / wyvern / src / main.js View on Github external
Vue.use(Vuex);

// Mixins
Vue.mixin({
  methods: mixins,
});

// Lodash
window._ = require('lodash');

/**
 * WP API
 * https://github.com/WP-API/node-wpapi
 */
window.wp = new WPAPI({ endpoint: config.root });
window.apiPromise = WPAPI.discover(config.base_url);

/**
 * Standard UI components
 */
Vue.component('menu-location', require('@/components/partials/menu-location'));
Vue.component('gallery', require('@/components/partials/gallery'));
Vue.component('lightbox', require('@/components/partials/lightbox'));
Vue.component('theme-header', require('@/components/partials/theme-header'));

// Running in dev mode, load routes from API
if (process.env.NODE_ENV !== 'production') {
  WPConfig.getConfig(data => {
    window.config = data;
    EventBus.$emit('config', window.config);
    router.addRoutes(setComponentsToRoutes(window.config.routes));
  });

wpapi

An isomorphic JavaScript client for interacting with the WordPress REST API

MIT
Latest version published 4 years ago

Package Health Score

50 / 100
Full package analysis

Popular wpapi functions