• Stars
    star
    126
  • Rank 275,632 (Top 6 %)
  • Language
    Go
  • License
    MIT License
  • Created over 8 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Golang client library for WP-API (Wordpress REST API)

go-wp-api

Golang client library for WP-API (Wordpress REST API)

Installation

go get github.com/sogko/go-wordpress

Usage

Quick example

package main

import (
	"github.com/sogko/go-wordpress"
	"net/http"
)

func main() {

  // create wp-api client
  client := wordpress.NewClient(&wordpress.Options{
    BaseAPIURL: API_BASE_URL, // example: `http://192.168.99.100:32777/wp-json/wp/v2`
    Username:   USER,
    Password:   PASSWORD,
  })
  	
  // for eg, to get current user (GET /users/me)
  currentUser, resp, body, _ := client.Users().Me()
  if resp.StatusCode != http.StatusOK {
    // handle error
  }
  
  // `body` will contain raw JSON body in []bytes
  
  // Or you can use your own structs (for custom endpoints, for example)
  // Below is the equivalent of `client.Posts().Get(100, nil)`
  var obj MyCustomPostStruct
  resp, body, err := client.Get("/posts/100", nil, &obj)
  // ...
  
  log.Println("Current user", currentUser)
}

For more examples, see package tests.

For list of supported/implemented endpoints, see Endpoints.md

Test

Note: Before running the tests, ensure that you have set up your test environment

Prerequisites

Setting up test environment

  • Install prequisits (see above)
  • Import ./test-data/go-wordpress.wordpress.2015-08-23.xml to your local test Wordpress installation
  • Upload at least one media to your Wordpress installation (Admin > Media > Upload)
  • Edit one (1) most recent Post to create a revision
  • Edit one (1) most recent Page to create a revision

Running test

# Set test enviroment
export WP_API_URL=http://192.168.99.100:32777/wp-json/wp/v2
export WP_USER=<user>
export WP_PASSWD=<password>

cd <path_to_package>/github.com/sogko/go-wordpress
go test

TODO

  • godoc documentation, so its easier for library users to map the REST APIs to library calls
  • Test comments API endpoint. (Currently, already implemented but not tested due to WP-API issues with creating comments reliably)
  • Support OAuth authentication

More Repositories

1

graphql-schema-language-cheat-sheet

GraphQL Shorthand Notation Cheat Sheet
1,328
star
2

slumber

A complete REST API server written in golang / go
Go
427
star
3

gulp-recipes

gulp-recipes
JavaScript
399
star
4

golang-relay-starter-kit

Barebones starting point for a Relay application with Golang GraphQL server
Go
136
star
5

todomvc-relay-go

React/Relay TodoMVC app, driven by a Golang GraphQL backend
JavaScript
66
star
6

node-osm-stream

Fast and flexible NodeJS-based streaming parser for OpenStreetMap (.osm) files powered by node-expat - @sogko
JavaScript
17
star
7

graphql-schemas

A collection of common and useful GraphQL Object schemas
15
star
8

slumber-books-api-example

An example REST-ful API server using slumber package written in golang
Go
11
star
9

gosg-graphql-go-demo

Demo and slides for GoSG Meetup #15 - May 2016
CSS
10
star
10

fossasia-2016-google-calendar

A quick and dirty little thing that takes FOSSASIA 2016 schedule and creates Google Calendars (and iCal .ics) out of it.
Go
9
star
11

data-gov-sg-graphql-go

A GraphQL endpoint for https://data.gov.sg real-time APIs (Go/Golang)
Go
8
star
12

arangojs-extended

Extended APIs for ArangoJS client library
JavaScript
6
star
13

slumber-users

slumber-users is a slumber-resource that implements slumber.IUser
Go
4
star
14

node-osm-tags-analysis

Analyse .osm tagged data using NodeJS and osmfilter
JavaScript
4
star
15

node-ckan-crawler

A simple and fast NodeJS based crawler for sites powered by CKAN http://ckan.org
JavaScript
3
star
16

react-starter

Pragmatic starter kit for React + ES6 + Babel + Webpack + Tape.
JavaScript
3
star
17

graphql-geojson-go

Go
2
star
18

pecker

Pecker is a modern assets management framework for your web application development.
JavaScript
2
star
19

humanable-json

JavaScript
1
star
20

generator-leaner

yoeman generator for LEANER stack (Lightweight & Leaner express-angular-node-requirejs full web application stack)
JavaScript
1
star
21

fossasia-2016-graphql-demo

Demo used to showcase GraphQL (on Go / Golang)
CSS
1
star
22

go-ratelimit

Golang package to ratelimit messages/connections per unit time
Go
1
star