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
Copy file name to clipboardExpand all lines: docs/getting_started.md
+7-3Lines changed: 7 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,14 @@
1
1
This guide provides a complete setup for a Crystal web application using the Grip framework, including project initialization, dependency setup, application code, server execution, testing, and auto-restart configuration.
2
2
3
3
## 1. Initialize a Crystal Project
4
+
4
5
```shell
5
6
# Initializes a new Crystal application named "demo" and navigates to its directory.
6
-
# Creates a project structure with shard.yml, src/, and lib/ directories.
7
7
crystal init app demo &&cd demo
8
8
```
9
9
10
10
## 2. Add Dependency to `shard.yml` and Install
11
+
11
12
```yaml
12
13
# shard.yml: Specifies project dependencies for the Crystal application.
13
14
name: demo
@@ -24,11 +25,11 @@ crystal: 1.0.0
24
25
25
26
dependencies:
26
27
grip: # Adds the Grip web framework as a dependency.
27
-
github: grip-framework/grip# Points to the Grip repository on GitHub.
28
+
github: grip-framework/grip
28
29
```
29
30
30
31
```shell
31
-
# Installs the dependencies listed in shard.yml, downloading Grip to lib/.
32
+
# Installs the dependencies listed in shard.yml
32
33
shards install
33
34
```
34
35
@@ -86,20 +87,23 @@ app.run
86
87
```
87
88
88
89
## 4. Run the Server
90
+
89
91
```shell
90
92
# Compiles and runs the Crystal application, starting the Grip server.
91
93
# The server listens on 0.0.0.0:4004 by default unless configured otherwise.
92
94
crystal src/demo.cr
93
95
```
94
96
95
97
## 5. Send a Request
98
+
96
99
```shell
97
100
# Sends an HTTP GET request to the root path of the running server.
98
101
# Expects a 201 response with a JSON body {"id": 1} and a Server header.
99
102
curl "http://0.0.0.0:4004/"
100
103
```
101
104
102
105
## 6. Auto-Restart Server
106
+
103
107
```shell
104
108
# Installs nodemon globally to watch for file changes and auto-restart the server.
Copy file name to clipboardExpand all lines: docs/index.md
+15Lines changed: 15 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,9 +3,13 @@ Grip is a lightweight microframework for building RESTful web applications in th
3
3
## Framework Features
4
4
5
5
-**Microframework Design**: Grip focuses on simplicity for building RESTful APIs, enabling rapid development while supporting complex applications through modular extensions.
6
+
6
7
-**Middleware ("Pipes")**: Integrated middleware, implemented as `HTTP::Handler` classes, processes and modifies request/response contexts (e.g., adding headers, authentication) before forwarding to endpoints.
8
+
7
9
-**Router**: Inspired by the [Phoenix framework](https://github.com/phoenixframework/phoenix), Grip’s router offers expressive routing with macros like `get`, `scope`, `pipe_through`, and `forward` for defining endpoints and pipelines.
10
+
8
11
-**Extensibility**: Developers can create custom middleware, controllers, and error handlers to tailor functionality to specific needs.
12
+
9
13
-**High Performance**: Optimized for speed, Grip delivers exceptional throughput, making it ideal for high-performance API development.
-**lib/**: Contains external libraries (e.g., Grip) installed via `shards install`, managed by Crystal’s dependency manager.
37
+
32
38
-**src/application.cr**: The application entry point, defining the `Application` class (inheriting from `Grip::Application`). It configures middleware via a `property handlers` array and sets up routes using macros like `get` or `forward`.
39
+
33
40
-**src/echo/**: Houses business logic, including database models, services, or other domain-specific functionality, ensuring separation from web concerns.
41
+
34
42
-**src/echo_web/**: Manages HTTP interactions, with controllers (e.g., `DemoController`) handling requests and views defining response formats (e.g., JSON, HTML).
43
+
35
44
-**shards.yml**: Specifies project metadata and dependencies, such as `grip: { github: grip-framework/grip }`.
36
45
37
46
## Example Setup
47
+
38
48
To create a Grip application with the above structure:
49
+
39
50
1. Initialize a Crystal project: `crystal init app echo && cd echo`.
51
+
40
52
2. Add Grip to `shards.yml`:
41
53
```yaml
42
54
dependencies:
43
55
grip:
44
56
github: grip-framework/grip
45
57
```
58
+
46
59
3. Install dependencies: `shards install`.
60
+
47
61
4. Define the application in `src/application.cr`, configuring handlers and routes (see previous examples for controller and route definitions).
62
+
48
63
5. Run the server: `crystal src/application.cr`.
49
64
50
65
This structure and Grip’s features provide a robust foundation for building scalable, high-performance RESTful applications in Crystal.
Copy file name to clipboardExpand all lines: docs/installation.md
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,17 +1,19 @@
1
1
To use the Grip framework in a Crystal application, you must add it as a dependency in the project’s `shard.yml` file and install it using the `shards` command. This ensures the framework is available for building RESTful web applications.
2
2
3
3
## 1. Update `shard.yml`
4
+
4
5
Add the Grip dependency to your project’s `shard.yml` file, located in the project root directory. This file specifies the project’s metadata and dependencies.
5
6
6
7
```yaml
7
8
# shard.yml: Configuration file for project dependencies and metadata.
8
9
dependencies:
9
-
grip:# Specifies the Grip microframework for building RESTful APIs.
10
+
grip:
10
11
github: grip-framework/grip # References the Grip repository on GitHub.
11
12
```
12
13
13
14
## 2. Install Dependencies
14
-
Run the following command in your terminal to install the dependencies listed in `shard.yml`:
15
+
16
+
Run the following command in your terminal:
15
17
16
18
```bash
17
19
# Installs dependencies specified in shard.yml, downloading Grip to the lib/ directory.
0 commit comments