<commit_before># Ethcore JSON-RPC

Rust implementation of JSON-RPC 2.0 Specification.
Transport-agnostic `core` and transport servers for `http`, `ipc` and `tcp`.

[![Build Status][travis-image]][travis-url]

[travis-image]: https://travis-ci.org/ethcore/jsonrpc.svg?branch=master
[travis-url]: https://travis-ci.org/ethcore/jsonrpc

[Documentation](http://ethcore.github.io/jsonrpc/jsonrpc/index.html)

## Sub-projects
- [jsonrpc-core](./core)
- [jsonrpc-http-server](./http)
- [jsonrpc-ipc-server](./ipc)
- [jsonrpc-tcp-server](./tcp)
- [jsonrpc-macros](./macros)
<commit_msg>Add examples to the README.md<commit_after># Ethcore JSON-RPC

Rust implementation of JSON-RPC 2.0 Specification.
Transport-agnostic `core` and transport servers for `http`, `ipc` and `tcp`.

[![Build Status][travis-image]][travis-url]

[travis-image]: https://travis-ci.org/ethcore/jsonrpc.svg?branch=master
[travis-url]: https://travis-ci.org/ethcore/jsonrpc

[Documentation](http://ethcore.github.io/jsonrpc/jsonrpc/index.html)

## Sub-projects
- [jsonrpc-core](./core)
- [jsonrpc-http-server](./http)
- [jsonrpc-ipc-server](./ipc)
- [jsonrpc-tcp-server](./tcp)
- [jsonrpc-macros](./macros)

## Examples

- [Core](./core/examples)
- [Macros](./macros/examples)

### Basic Usage (with HTTP transport)

```rust
extern crate jsonrpc_core;
extern crate jsonrpc_http_server;

use jsonrpc_core::{IoHandler, Value, Params};
use jsonrpc_http_server::{ServerBuilder};

fn main() {
	let mut io = IoHandler::new();
	io.add_method("say_hello", |_params: Params| {
		Ok(Value::String("hello".to_string()))
	});

	let server = ServerBuilder::new(io)
		.start_http(&"127.0.0.1:3030".parse().unwrap())
		.unwrap();

	server.wait().unwrap();
}
```

### Basic usage with macros

```rust
extern crate jsonrpc_core;
#[macro_use]
extern crate jsonrpc_macros;

use jsonrpc_core::Error;

build_rpc_trait! {
	pub trait Rpc {
		/// Adds two numbers and returns a result
		#[rpc(name = "add")]
		fn add(&self, u64, u64) -> Result<u64, Error>;
	}
}

pub struct RpcImpl;
impl Rpc for RpcImpl {
	fn add(&self, a: u64, b: u64) -> Result<u64, Error> {
		Ok(a + b)
	}
}


fn main() {
	let mut io = jsonrpc_core::IoHandler::new();
	io.extend_with(RpcImpl.to_delegate())
}

{'fraction_non_alphanumeric': 0.1873873873873874, 'fraction_numerical': 0.011711711711711712, 'mean_word_length': 4.694871794871795, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6375761', 'n_tokens_mistral': 868, 'n_tokens_neox': 855, 'n_words': 162}