Swagger - Swagger contains a OpenAPI / Swagger universal documentation generator and server handler.

Swagger is low-level library which generate output compatible with Swagger / OpenAPI Spec 3.0.1, and wrapped many friendly APIs let developer understand and use it easier.

builder = Swagger::Builder.new(
  title: "Simple App API Demo",
  version: "1.0.0",
  description: "Simple App API Demo document written by Crystal",
  terms_url: "https://github.com/icyleaf/swagger",
  license: Swagger::License.new("MIT", "https://opensource.org/licenses/MIT"),
  contact: Swagger::Contact.new("icyleaf", "icyleaf.cn@gmail.com", "http://icyleaf.com")
)

builder.add(Swagger::Object.new("User", "object", [
    Swagger::Property.new("id", "integer", "int32", example: 1),
    Swagger::Property.new("nickname", example: "icyleaf wang"),
    Swagger::Property.new("username", example: "icyleaf"),
    Swagger::Property.new("email", example: "icyleaf.cn@gmail.com"),
    Swagger::Property.new("bio", "Personal bio"),
]))

builder.add(Swagger::Controller.new("Users", "User Resources", [
  Swagger::Action.new("get", "/users", "List users", parameters: [
    Swagger::Parameter.new("page", "query", "integer", "Current page", default_value: 1, format: "int32"),
    Swagger::Parameter.new("limit", "query", "integer", "How many items to return at one time (max 100)", default_value: 50, format: "int32"),
  ]),
  Swagger::Action.new("get", "/users/{id}", "Get user by id", parameters: [Swagger::Parameter.new("id", "path")], responses: [
    Swagger::Response.new("200", "Success response"),
    Swagger::Response.new("404", "Not found user")
  ], request: Swagger::Request.new("User")),
  Swagger::Action.new("post", "/users", "Create user",
    request: Swagger::Request.new([
      Swagger::Property.new("username", required: true, description: "The name of user"),
      Swagger::Property.new("email", "string", required: true, description: "Email"),
      Swagger::Property.new("gender", "integer", default_value: 0, description: "Man or Female"),
      Swagger::Property.new("password", required: true, description: "Set your password"),
      Swagger::Property.new("confirm_password", required: true, description: "Confirm password"),
    ], "Form data", "application/x-www-form-urlencoded"),
    responses: [
      Swagger::Response.new("200", "Success response", "User"),
      Swagger::Response.new("404", "Not found user")
    ]
  ),
  Swagger::Action.new("get", "/user/{id}", "Get user by id", parameters: [Swagger::Parameter.new("id", "path")], responses: [
    Swagger::Response.new("200", "Success response"),
    Swagger::Response.new("404", "Not found user")
  ], deprecated: true)
]))

builder.add(Swagger::Server.new("http://swagger.dev:{port}/{version}/api", "Development", [
  Swagger::Server::Variable.new("port", "3000", ["3000"], "API port"),
  Swagger::Server::Variable.new("version", "v2", ["v2", "v3"], description: "API version"),
]))
builder.add(Swagger::Server.new("http://example.com/api", "Production"))

Swagger::HTTP::Server.run(builder.built)

https://github.com/icyleaf/swagger

Load .env files in crystal

https://github.com/drum445/dotenv

Loads .env file in Crystal and optionally loads them directly into your ENV var: https://crystal-lang.org/api/0.27.0/ENV.html Will always return the .env file as a hash regardless of whether you chose to load into your ENV or not.

Example of .env file:

ENV=dev
PORT=3000
LOGGING=true
CORS=*

DB_DRIVER=mysql
DB_USERNAME=root
DB_PASSWORD=password
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=test
require "dotenv"

Dotenv.load # => {"ENV" => "dev", "PORT" => "3000", "LOGGING" => "true", "CORS" => "*", "DB_DRIVER" => "mysql", "DB_USERNAME" => "root", "DB_PASSWORD" => "password", "DB_HOST" => "localhost", "DB_PORT" => "3306", "DB_DATABASE" => "test"}

Extensible annotation based serialization/deserialization/validation library

https://github.com/blacksmoke16/CrSerializer

JSON (and later YAML) serializer and validator inspired by JMS Serializer Annotations and Symfony Validation Constraint Annotations.

Goals

  • Be a compliment to, not a replacement for, JSON::Serializable or YAML::Serializable
  • Extensible and customizable to fit all use cases
  • Make working with JSON APIs in Crystal much easier
  • Be easy to adopt and start using effectively
  • Work out of the box with most ORMs (assuming they are compatible with JSON::Serializable/annotations)

Pure-Crystal implementation of Neo4j's Bolt protocol

https://github.com/jgaskins/neo4j.cr

Crystal implementation of a Neo4j driver using the Bolt protocol.

require "neo4j"

# The `ssl` option defaults to `true` so you don't accidentally send the
# password to your production DB in cleartext.
connection = Neo4j::Bolt::Connection.new(
  "bolt://neo4j:password@localhost:7687",
  ssl: false,
)

connection.execute("
  MATCH (order:Order)-[:ORDERS]->(product:Product)
  RETURN order, collect(product)
  LIMIT 10
")