Sample API to diagram editing using shapes (rectangle and circle)
- bundle install
-
Install and configure PostgreSQL
-
Copy database config
cp config/database.yml.sample config/database.yml
-
Prepare database
rake db:setup && rake db:seed
- Run rails server, eg.
rails s
{
"diagram": {
"id": 1,
"name": "white-board",
"shapes": []
}
}
{
"shape": {
"label": "purple-rect",
"kind": "rectangle",
"properties" : {
"width": 15,
"heigth": 10,
"center_x": 0,
"center_y": 0,
"color": "purple"
}
}
}
{
"shape": {
"label": "my-sample-circle",
"kind": "circle",
"properties" : {
"radius": 10,
"center_x": 0,
"center_y": 0,
"color": "white"
}
}
}
POST /api/v1/1/diagrams
{
"diagram": {
"name": "magnetic-board"
}
}
{
"diagram": {
"id": 1,
"name": "magnetic-board",
"shapes": []
}
}
PUT /api/v1/diagrams/1
{
"diagram": {
"name": "white-magnetic-board"
}
}
{
"diagram": {
"id": 1,
"name": "white-magnetic-board",
"shapes": []
}
}
PUT /api/v1/diagrams/1
{}
POST /api/v1/diagrams/1/shapes
{
"shape": {
"label": "purple-square",
"kind": "rectangle",
"properties" : {
"width": 10,
"heigth": 10,
"color": "purple"
}
}
}
{
"shape": {
"id": 1,
"label": "purple-square",
"kind": "rectangle",
"properties": {
"color": "purple",
"width": 10,
"heigth": 10
}
}
}
PUT /api/v1/diagrams/1/shapes/1
{
"shape": {
"label": "purple-square-big",
"properties" : {
"width": 100,
"heigth": 100
}
}
}
{
"shape": {
"id": 1,
"label": "purple-square-big",
"kind": "circle",
"properties": {
"width": 100,
"heigth": 100
}
}
}
DELETE /api/v1/diagrams/1/shapes/1
{}