note-api-by-crystal
Version, currently master branch1 version
- master branchlatestAug 23, 2018
github.com/shiba-hiro/note-api-by-crystal
note-api-by-crystal is a sample web api project implemented by Crystal
Installation
# Add this to your shard.yml
dependencies:
note-api-by-crystal:
github: shiba-hiro/note-api-by-crystal
branch: mastermaster is a branch, not a release, so this tracks it rather than pinning a version.
Then run:
shards installshard.yml
- Crystal
0.26.0- License
- MIT
- Author
- Shibata Hirofumi <shiba-hiro>
- Target
note-apifrom src/note-api.cr
Dependencies
Runtime Dependencies
- kemal*github: kemalcr/kemal
- mysql*github: crystal-lang/crystal-mysql
- crecto*github: fridgerator/crecto
Development Dependencies
- spec-kemal*github: kemalcr/spec-kemaldev
README
note-api-by-crystal
note-api-by-crystal is a sample web api project implemented by Crystal.
Requirements
-
Install Crystal
https://crystal-lang.org/docs/installation/ -
Run database
You can refer here.
Quick start
Can start by simply installing libs and executing it.
$ git clone https://github.com/shiba-hiro/note-api-by-crystal
$ cd note-api-by-crystal
$ shards install
$ crystal run src/note-api.cr
You can check state by health-check endpoint.
This example use httpie, of course curl is also OK.
$ http GET http://localhost:3000/health-check
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 128
Content-Type: application/json
X-Powered-By: Kemal
{
"app": {
"message": "Application is running.",
"success": true
},
"db_connection": {
"message": "Database is available.",
"success": true
}
}
Usage
note-api supports simple CRUD operations.
$ http POST http://localhost:3000/v1/notes title="My First Note" content="I started to take note."
HTTP/1.1 201 Created
Connection: keep-alive
Content-Length: 195
Content-Type: application/json
X-Powered-By: Kemal
{
"content": "I started to take note.",
"created_at": "2018-06-13T14:58:38.231+00:00",
"id": "bf8f34a5-4374-4a18-9704-8c3aa29d336d",
"title": "My First Note",
"updated_at": "2018-06-13T14:58:38.231+00:00"
}
$ http GET http://localhost:3000/v1/notes/bf8f34a5-4374-4a18-9704-8c3aa29d336d
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 195
Content-Type: application/json
X-Powered-By: Kemal
{
"content": "I started to take note.",
"created_at": "2018-06-13T14:58:38.231+00:00",
"id": "bf8f34a5-4374-4a18-9704-8c3aa29d336d",
"title": "My First Note",
"updated_at": "2018-06-13T14:58:38.231+00:00"
}
$ http PUT http://localhost:3000/v1/notes/bf8f34a5-4374-4a18-9704-8c3aa29d336d title="My First Note" content="I started to take note. But it's difficult to continue everyday..."
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 238
Content-Type: application/json
X-Powered-By: Kemal
{
"content": "I started to take note. But it's difficult to continue everyday...",
"created_at": "2018-06-13T14:58:38.231+00:00",
"id": "bf8f34a5-4374-4a18-9704-8c3aa29d336d",
"title": "My First Note",
"updated_at": "2018-06-13T15:03:40.739+00:00"
}
$ http DELETE http://localhost:3000/v1/notes/bf8f34a5-4374-4a18-9704-8c3aa29d336d
HTTP/1.1 204 No Content
Connection: keep-alive
Content-Length: 0
Content-Type: application/json
X-Powered-By: Kemal
Test
A. Execute spec programs
$ KEMAL_ENV=test crystal spec
B. Execute newman script
You can refer here.
Run as a Docker container
Insert environment variables on run phase.
$ sudo docker build . -t note-api
$ sudo docker run -dt -p 80:80 -e PORT=80 -e MYSQL_HOST=0.0.0.0 -e KEMAL_ENV=production --name note-api note-api
Libraries
Kemal, which is a simple web framework.
Kemal
Crecto as a database wrapper.
Crecto
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This branch
- Branch
master- Seen
- Aug 23, 2018
- Crystal
0.26.0- Indexed
- yes
Dependents
No indexed shard depends on this one yet.
Repository
github.com/shiba-hiro/note-api-by-crystal
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 15, 2026
- Synced
- Aug 15, 2026
- Versions
- 1