Skip to content

Commit 4a7524e

Browse files
committed
Update documentation, fix formatting
1 parent 425c482 commit 4a7524e

14 files changed

Lines changed: 67 additions & 28 deletions

docs/advanced_routing.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ class DemoController
2727
end
2828
2929
# Application configures and runs a Grip web application.
30-
class Application < Grip::Application
30+
class Application
31+
include Grip::Application
32+
3133
# List of HTTP handlers for processing incoming requests.
3234
property handlers : Array(HTTP::Handler) = [
3335
Grip::Handlers::Pipeline.new, # Manages the request pipeline.

docs/application.md

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Application module is a building block which initializes the crucial parts of th
33
```crystal
44
# Application is a building class that initializes the core components of the Grip web framework.
55
# It manages the main handler stack and the HTTP server.
6-
class Application < Grip::Application
6+
class Application
77
include Grip::Application
88
99
# List of HTTP handlers for processing incoming requests.
@@ -16,13 +16,7 @@ class Application < Grip::Application
1616
# Defines the host address of the server.
1717
# @return [String] The host address (e.g., "0.0.0.0").
1818
def host : String
19-
DEFAULT_HOST
20-
end
21-
22-
# Defines the root path for routing (placeholder for custom implementation).
23-
# @return [String] The root path for the application.
24-
def root : String
25-
"/"
19+
"0.0.0.0"
2620
end
2721
2822
# Placeholder for custom configuration or logic.
@@ -34,13 +28,13 @@ class Application < Grip::Application
3428
# Defines the port on which the server listens.
3529
# @return [Int32] The port number (e.g., 4004).
3630
def port : Int32
37-
DEFAULT_PORT
31+
4004
3832
end
3933
4034
# Determines if the server reuses the port.
4135
# @return [Bool] True if port reuse is enabled, false otherwise.
4236
def reuse_port : Bool
43-
DEFAULT_REUSE_PORT
37+
true
4438
end
4539
4640
# Defines the SSL key file location for the application.

docs/basic_routing.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ class DemoController
1414
end
1515
1616
# Application configures and runs a Grip web application.
17-
class Application < Grip::Application
17+
class Application
18+
include Grip::Application
19+
1820
# List of HTTP handlers for processing incoming requests.
1921
property handlers : Array(HTTP::Handler) = [
20-
Grip::Handlers::Pipeline.new, # Manages the request pipeline.
21-
Grip::Handlers::HTTP.new # Handles core HTTP protocol logic.
22+
Grip::Handlers::HTTP.new # Handles core HTTP protocol logic.
2223
] of HTTP::Handler
2324
2425
# Initializes the application and configures routes.

docs/error_handling.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ class ForbiddenController
3232
end
3333
3434
# Application configures the Grip web application with error handlers and routes.
35-
class Application < Grip::Application
35+
class Application
36+
include Grip::Application
37+
3638
# Defines the array of HTTP handlers for processing requests.
3739
property handlers : Array(HTTP::Handler) = [
3840
Grip::Handlers::Exception.new, # Handles exceptions using defined error controllers.
@@ -91,7 +93,9 @@ class FallbackController
9193
end
9294
9395
# Application configures the Grip web application with a fallback error handler.
94-
class Application < Grip::Application
96+
class Application
97+
include Grip::Application
98+
9599
# Defines the array of HTTP handlers for processing requests.
96100
property handlers : Array(HTTP::Handler) = [
97101
Grip::Handlers::Exception.new, # Handles exceptions using defined error controllers.

docs/forward.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ class Authorization
2222
end
2323
2424
# Application configures the Grip web application with handlers and routes.
25-
class Application < Grip::Application
25+
class Application
26+
include Grip::Application
27+
2628
# Defines the array of HTTP handlers for processing requests.
2729
property handlers : Array(HTTP::Handler) = [
2830
Grip::Handlers::HTTP.new, # Handles core HTTP protocol logic.

docs/getting_started.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
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.
22

33
## 1. Initialize a Crystal Project
4+
45
```shell
56
# Initializes a new Crystal application named "demo" and navigates to its directory.
6-
# Creates a project structure with shard.yml, src/, and lib/ directories.
77
crystal init app demo && cd demo
88
```
99

1010
## 2. Add Dependency to `shard.yml` and Install
11+
1112
```yaml
1213
# shard.yml: Specifies project dependencies for the Crystal application.
1314
name: demo
@@ -24,11 +25,11 @@ crystal: 1.0.0
2425

2526
dependencies:
2627
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
2829
```
2930
3031
```shell
31-
# Installs the dependencies listed in shard.yml, downloading Grip to lib/.
32+
# Installs the dependencies listed in shard.yml
3233
shards install
3334
```
3435

@@ -86,20 +87,23 @@ app.run
8687
```
8788

8889
## 4. Run the Server
90+
8991
```shell
9092
# Compiles and runs the Crystal application, starting the Grip server.
9193
# The server listens on 0.0.0.0:4004 by default unless configured otherwise.
9294
crystal src/demo.cr
9395
```
9496

9597
## 5. Send a Request
98+
9699
```shell
97100
# Sends an HTTP GET request to the root path of the running server.
98101
# Expects a 201 response with a JSON body {"id": 1} and a Server header.
99102
curl "http://0.0.0.0:4004/"
100103
```
101104

102105
## 6. Auto-Restart Server
106+
103107
```shell
104108
# Installs nodemon globally to watch for file changes and auto-restart the server.
105109
sudo npm install -g nodemon

docs/index.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ Grip is a lightweight microframework for building RESTful web applications in th
33
## Framework Features
44

55
- **Microframework Design**: Grip focuses on simplicity for building RESTful APIs, enabling rapid development while supporting complex applications through modular extensions.
6+
67
- **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+
79
- **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+
811
- **Extensibility**: Developers can create custom middleware, controllers, and error handlers to tailor functionality to specific needs.
12+
913
- **High Performance**: Optimized for speed, Grip delivers exceptional throughput, making it ideal for high-performance API development.
1014

1115
## Recommended Project Structure
@@ -28,23 +32,34 @@ Echo/ # Project root directory
2832
```
2933

3034
### Structure Details
35+
3136
- **lib/**: Contains external libraries (e.g., Grip) installed via `shards install`, managed by Crystal’s dependency manager.
37+
3238
- **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+
3340
- **src/echo/**: Houses business logic, including database models, services, or other domain-specific functionality, ensuring separation from web concerns.
41+
3442
- **src/echo_web/**: Manages HTTP interactions, with controllers (e.g., `DemoController`) handling requests and views defining response formats (e.g., JSON, HTML).
43+
3544
- **shards.yml**: Specifies project metadata and dependencies, such as `grip: { github: grip-framework/grip }`.
3645

3746
## Example Setup
47+
3848
To create a Grip application with the above structure:
49+
3950
1. Initialize a Crystal project: `crystal init app echo && cd echo`.
51+
4052
2. Add Grip to `shards.yml`:
4153
```yaml
4254
dependencies:
4355
grip:
4456
github: grip-framework/grip
4557
```
58+
4659
3. Install dependencies: `shards install`.
60+
4761
4. Define the application in `src/application.cr`, configuring handlers and routes (see previous examples for controller and route definitions).
62+
4863
5. Run the server: `crystal src/application.cr`.
4964

5065
This structure and Grip’s features provide a robust foundation for building scalable, high-performance RESTful applications in Crystal.

docs/installation.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
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.
22

33
## 1. Update `shard.yml`
4+
45
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.
56

67
```yaml
78
# shard.yml: Configuration file for project dependencies and metadata.
89
dependencies:
9-
grip: # Specifies the Grip microframework for building RESTful APIs.
10+
grip:
1011
github: grip-framework/grip # References the Grip repository on GitHub.
1112
```
1213
1314
## 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:
1517
1618
```bash
1719
# Installs dependencies specified in shard.yml, downloading Grip to the lib/ directory.

docs/pipe_middleware.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ class DemoController
3434
end
3535
3636
# Application configures and runs a Grip web application.
37-
class Application < Grip::Application
37+
class Application
38+
include Grip::Application
39+
3840
# Defines the array of HTTP handlers for processing requests.
3941
property handlers : Array(HTTP::Handler) = [
4042
Grip::Handlers::Pipeline.new, # Manages the request pipeline for middleware execution.

docs/runtime_flags.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Configuration flags
2+
23
1. Flag which enables HTTPS:
34

45
```bash

0 commit comments

Comments
 (0)