https://github.com/f/kreal
Kreal is a model sharing & RPC library built on and works with Kemal seamlessly.
https://github.com/f/kreal
Last synced: over 1 year ago
JSON representation
Kreal is a model sharing & RPC library built on and works with Kemal seamlessly.
- Host: GitHub
- URL: https://github.com/f/kreal
- Owner: f
- License: mit
- Created: 2016-03-21T16:02:51.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-03-28T03:15:26.000Z (about 9 years ago)
- Last Synced: 2025-01-11T11:48:02.400Z (over 1 year ago)
- Language: HTML
- Homepage:
- Size: 16.6 KB
- Stars: 44
- Watchers: 6
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

# Kreal
Kreal is a model sharing & RPC library built on and works with [Kemal](http://github.com/sdogruyol/kemal) seamlessly with slick debugging interface.
## Simple Tutorial
### 1. Create your remote models.
```crystal
# 1. Load Kreal!
require "kreal"
# 2. Create your class
class Maths
# Share your method to call remotely
share :square
# Remote method must have arguments.
def self.square(args)
args[0] * args[0]
end
end
# Register your remote procedure
kreal Maths
# Rest of your Kemal app...
get "/" do
# do not forget to load scripts/kreal.js
end
# Do not forget to run Kemal.
Kemal.run
```
### 2. Use your models via JavaScript API.
Add this to your scripts:
```html
```
Call your remote methods via **Kreal** magically.
```js
(new Kreal).connect(function (KR) {
// Call your function with a callback!
KR.Maths.square(2, function (result) {
console.log(result); // "4"
});
});
```
## Example App
```
crystal run ./example/example.cr
```
Open [localhost:3000/kreal](http://localhost:3000/kreal)
## Kreal Debugger
Kreal debugger enables itself when Kemal is on debug mode.

```
crystal build src/yourapp.cr
# Use the parameters of Kemal since it's built on Kemal.
yourapp -e development
[development] Kemal is ready to lead at http://0.0.0.0:3000
```
Now you have a debugging view at [http://0.0.0.0:3000/kreal](http://0.0.0.0:3000/kreal)
### Let's build a simple example
Let's build a simple **OS bridge**!
```crystal
class OSBridge
share :run
def self.run(args)
# Run command at os.
`#{args[0]}`
end
end
kreal OSBridge
```
Done!
Now use it from your JavaScript! 👌

## Installation
Add this to your application's `shard.yml`:
```yaml
dependencies:
kreal:
github: f/kreal
```
## Contributing
1. Fork it ( https://github.com/f/kreal/fork )
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
4. Push to the branch (git push origin my-new-feature)
5. Create a new Pull Request
## Contributors
- [@f](https://github.com/f) Fatih Kadir Akın - creator, maintainer