You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| Rails |https://rubyonrails.org/| Framework for modern web applications |
11
+
| Puma |https://puma.io/| Web server for executing your Rails application |
11
12
| SQLite |https://www.sqlite.org/index.html| The lightweight database |
12
13
13
14
## Build
14
-
TODO
15
+
Builds are performed using the `Rakefile` provided in the project root.
15
16
16
17
#### CLI
17
-
TODO
18
+
In order to buid from the command-line, you'll need to have Ruby (3.0+) and Rails (6.1.4+) installed on your system.
19
+
20
+
:point_up: NOTE: To initially build the project, you may need to run the `rake` command to install the tools utilized for builds.
21
+
22
+
Once built, you can **migrate** the database scripts and run the application:
23
+
```shell script
24
+
$ rails db:setup; rails db:migrate; rails server
25
+
```
18
26
19
27
#### Docker
20
-
TODO
28
+
For those who do not have the Ruby and Rails dependencies installed locally, [Docker](https://hub.docker.com/) is an option to build the application and run the application within a container.
29
+
30
+
To execute the Rails application, use the following Docker command to create your image:
Once the the image is available, you can simply run the provided script which will open a browser to access the service
35
+
at http://localhost:3000/api/hello .
36
+
37
+
```shell script
38
+
$ ./docker-run.sh
39
+
```
40
+
:point_up: NOTE: the `docker-run.sh` script is setup to **not** maintain state between executions. This means each
41
+
time you start the container, you will be starting with a freshly created database.
21
42
22
43
## Using the Application
23
-
TODO
44
+
:point_up: TIP: Use the very cool [HTTPie](https://httpie.org/) application for testing locally from the command-line.
45
+
46
+
Execute a `GET` command to retrieve the available _places_ from the database.
47
+
```shell script
48
+
$ http GET :3000/api/places
49
+
50
+
HTTP/1.1 200 OK
51
+
Content-Type: application/json; charset=utf-8
52
+
53
+
[]
24
54
```
25
-
rails new weesvc-rails-api --api
26
-
rails generate model Place name:string description:string
27
-
rails generate controller api/places
28
-
rails db:setup
29
-
rails db:migrate
30
-
rails server
55
+
Add a _place_ into the database using a `POST` command.
56
+
```shell script
57
+
$ http POST :3000/api/places name=NISC description="NISC Lake St. Louis Office" latitude:=38.7839 longitude:=90.7878
58
+
59
+
HTTP/1.1 200 OK
60
+
Content-Type: application/json; charset=utf-8
61
+
62
+
{
63
+
"created_at": "2021-11-14T19:07:38.049Z",
64
+
"description": "NISC Lake St. Louis Office",
65
+
"id": 1,
66
+
"latitude": 38.7839,
67
+
"longitude": 90.7878,
68
+
"name": "NISC",
69
+
"updated_at": "2021-11-14T19:07:38.049Z"
70
+
}
31
71
```
32
-
Thanks to https://medium.com/@oliver.seq/creating-a-rest-api-with-rails-2a07f548e5dc
72
+
Run the `GET` command again to retrieve _places_ which now include your newly added _place_!
73
+
```shell script
74
+
$ http GET :3000/api/places
33
75
76
+
HTTP/1.1 200 OK
77
+
Content-Type: application/json; charset=utf-8
78
+
79
+
[
80
+
{
81
+
"created_at": "2021-11-14T19:10:32.042Z",
82
+
"description": "NISC Lake St. Louis Office",
83
+
"id": 1,
84
+
"latitude": 38.7839,
85
+
"longitude": 90.7878,
86
+
"name": "NISC",
87
+
"updated_at": "2021-11-14T19:10:32.042Z"
88
+
}
89
+
]
90
+
```
91
+
Use the `PATCH` command to update a specific value. For example we'll update the `Description` as follows:
92
+
```shell script
93
+
$ http PATCH :3000/api/places/1 description="Lake St. Louis"
34
94
95
+
HTTP/1.1 200 OK
96
+
Content-Type: application/json; charset=utf-8
35
97
98
+
{
99
+
"created_at": "2021-11-14T19:10:32.042Z",
100
+
"description": "Lake St. Louis",
101
+
"id": 1,
102
+
"latitude": 38.7839,
103
+
"longitude": 90.7878,
104
+
"name": "NISC",
105
+
"updated_at": "2021-11-14T19:13:16.232Z"
106
+
}
107
+
```
108
+
This returns the newly "patched" version of the _place_. Next we'll remove the row using the `DELETE` method.
109
+
```shell script
110
+
$ http DELETE :3000/api/places/1
111
+
112
+
HTTP/1.1 200 OK
113
+
Content-Type: application/json; charset=utf-8
114
+
115
+
{
116
+
"message": "Place successfully deleted."
117
+
}
118
+
```
36
119
37
120
## API Compliance
38
121
A core requirement for all _WeeSVC_ implementations is to implement the same API which are utilized for benchmark comparisons. To ensure compliance with the required API, [k6](https://k6.io/) is utilized within the [Workbench](https://github.com/weesvc/workbench) project.
0 commit comments