How to use the wpapi 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 bitterendio / wyvern / src / main.js View on Github external
// Vuex
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));
github outlandishideas / kasia / test / plugin.js View on Github external
const plugin = () => ({
    sagas: [pluginSaga],
    reducers: {
      [testActionType]: (state) => {
        countHitPluginOwnActionTypeReducer++
        return state
      },
      [ActionTypes.RequestComplete]: (state) => {
        countHitPluginNativeActionTypeReducer++
        return state
      }
    }
  })

  const { kasiaReducer, kasiaSagas } = kasia({
    wpapi: new Wpapi({ endpoint: '' }),
    plugins: [plugin]
  })

  const rootReducer = combineReducers(kasiaReducer)
  const store = createStore(rootReducer)

  return { store, kasiaSagas }
}
github outlandishideas / kasia / test / util / preload.js View on Github external
function setup (keyEntitiesBy) {
  queryCounter.reset()

  const { kasiaReducer, kasiaSagas } = kasia({
    wpapi: new Wpapi({ endpoint: '123' }),
    keyEntitiesBy
  })

  const sagaMiddleware = createSagaMiddleware()
  const createStore = compose(applyMiddleware(sagaMiddleware))(_createStore)
  const store = createStore(combineReducers(kasiaReducer), initialState(keyEntitiesBy))
  const runSaga = sagaMiddleware.run

  sagaMiddleware.run(function * () {
    yield kasiaSagas
  })

  store.runSaga = runSaga

  return { store, runSaga }
}
github postlight / headless-wp-starter / frontend / pages / post.js View on Github external
import React, { Component } from 'react';
import Error from 'next/error';
import Menu from '../components/Menu';
import WPAPI from 'wpapi';
import Layout from '../components/Layout';
import PageWrapper from '../components/PageWrapper';
import Config from '../config';

const wp = new WPAPI({ endpoint: Config.apiUrl });

class Post extends Component {
  static async getInitialProps(context) {
    const { slug, apiRoute } = context.query;

    let apiMethod = wp.posts();

    switch (apiRoute) {
      case 'category':
        apiMethod = wp.categories();
        break;
      case 'page':
        apiMethod = wp.pages();
        break;
      default:
        break;
github blivesta / wp-react-spa-boilerplate / src / client / pages / PostsDetail.js View on Github external
import React from 'react'
import ReactCSSTransitionGroup from 'react-addons-css-transition-group'
import DocumentTitle from 'react-document-title'
import Wpapi from 'wpapi'

const WP_PARAMETERS = global.WP_PARAMETERS
const wp = new Wpapi({ endpoint: WP_PARAMETERS.API })

class PostsDetail extends React.Component {

  constructor () {
    super()
    this.state = {
      title: '',
      content: ''
    }
  }

  render () {
    return (
      
        <main>
          </main>
github blivesta / wp-react-spa-boilerplate / src / client / pages / Posts.js View on Github external
import React, { Component } from 'react'
import ReactCSSTransitionGroup from 'react-addons-css-transition-group'
import { Link } from 'react-router'
import DocumentTitle from 'react-document-title'
import Wpapi from 'wpapi'

const WP_PARAMETERS = global.WP_PARAMETERS
const wp = new Wpapi({ endpoint: WP_PARAMETERS.API })

class Posts extends Component {
  constructor () {
    super()
    this.state = {
      title: 'Posts List',
      data: []
    }
  }

  componentDidMount (pageNum = 1) {
    wp.posts().page(pageNum).perPage(WP_PARAMETERS.POSTS_PER_PAGE).embed().then((res) => {
      this.setState({
        data: res
      })
    }).catch((err) => {
github blivesta / wp-react-spa-boilerplate / src / client / actions / index.js View on Github external
import {
  REQUEST_API,
  RECEIVE_ARCHIVES,
  RECEIVE_PAGE,
  WP_API,
  WP_POSTS_PER_PAGE,
  WP_PAGE_ON_FRONT
} from '../constants'

import Wpapi from 'wpapi'
const wp = new Wpapi({ endpoint: WP_API })

function requestApi (loading) {
  return {
    type: REQUEST_API,
    payload: {
      loading: loading
    }
  }
}

function receiveArchive (pageNum, totalPages, posts) {
  return {
    type: RECEIVE_ARCHIVES,
    payload: {
      pageNum: pageNum,
      totalPages: totalPages,
github postlight / headless-wp-starter / frontend / pages / index.js View on Github external
import React, { Component } from 'react';
import Link from 'next/link';
import Router from 'next/router';
import WPAPI from 'wpapi';
import Layout from '../components/Layout';
import PageWrapper from '../components/PageWrapper';
import Menu from '../components/Menu';
import Config from '../config';
import Logo from '../static/images/starter-kit-logo.svg';

const wp = new WPAPI({ endpoint: Config.apiUrl });

const headerImageStyle = {
  marginTop: 50,
  marginBottom: 50,
};

const tokenExpired = () => {
  if (process.browser) {
    localStorage.removeItem(Config.AUTH_TOKEN);
  }
  wp.setHeaders('Authorization', '');
  Router.push('/login');
};

class Index extends Component {
  state = {
github yashha / wp-nuxt / lib / module / sitemap.js View on Github external
routes: async () => {
        const postsBasePath = options.postsBasePath

        const wpapi = new WPAPI(this.options.wp)

        let posts = []
        try {
          posts = await getAll(wpapi.posts(100))
        } catch (e) {
          throw e
        }

        let pages = posts.map(item => {
          return {
            url: `${postsBasePath}${item.slug}`,
            lastmodISO: new Date(item.modified).toISOString()
          }
        })

        pages = pages.concat(this.options.router.routes.map(route => route.path))

wpapi

An isomorphic JavaScript client for interacting with the WordPress REST API

MIT
Latest version published 3 years ago

Package Health Score

53 / 100
Full package analysis

Popular wpapi functions