An open API service indexing awesome lists of open source software.

https://github.com/mushroomsir/jsonrpc

Move to https://github.com/teambition/jsonrpc-go
https://github.com/mushroomsir/jsonrpc

simple-api

Last synced: about 1 month ago
JSON representation

Move to https://github.com/teambition/jsonrpc-go

Awesome Lists containing this project

README

          

# jsonrpc

[![Build Status](https://travis-ci.org/mushroomsir/jsonrpc.svg?branch=master)](https://travis-ci.org/mushroomsir/jsonrpc)
[![Coverage Status](http://img.shields.io/coveralls/mushroomsir/jsonrpc.svg?style=flat-square)](https://coveralls.io/r/mushroomsir/jsonrpc)
[![License](http://img.shields.io/badge/license-mit-blue.svg?style=flat-square)](https://raw.githubusercontent.com/mushroomsir/jsonrpc/master/LICENSE)
[![GoDoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](http://godoc.org/github.com/mushroomsir/jsonrpc)

jsonrpc is an golang implementation just for parse and serialize JSON-RPC2 messages, it's easy to integration with your any application.

Inspired by [https://github.com/teambition/jsonrpc-lite](https://github.com/teambition/jsonrpc-lite) and [JSON-RPC 2.0 specifications](http://jsonrpc.org/specification)
## Installation
```go
go get github.com/mushroomsir/jsonrpc
```

## API
#### jsonrpc.Request(id, method[, params])
Creates a JSON-RPC 2.0 message structures
- `id`: {String|Int|nil}
- `method`: {String}
- `params`: {interface{}}, optional
```go
val, err := jsonrpc.Request(123, "update")
{
"jsonrpc": "2.0",
"method": "update",
"id": 123
}
```
#### jsonrpc.Request2(method[, params])
Creates a JSON-RPC 2.0 message structures, the id is automatic generation by strconv.FormatInt(rand.Int63(), 10)
- `method`: {String}
- `params`: {interface{}}, optional
```go
val, err := jsonrpc.Request("update")
{
"jsonrpc": "2.0",
"method": "update",
"id": randnum
}
```
#### jsonrpc.Notification(method[, params])
Creates a JSON-RPC 2.0 notification message structures
- `method`: {String}
- `params`: {interface{}}, optional
```go
val, err = jsonrpc.Notification("update")
{
"jsonrpc": "2.0",
"method": "update"
}
```