Procyon

Procyon

  • Documentation
  • Modules
  • Help
  • Blog

›Getting Started

Getting Started

  • Introduction
  • Quickstart
  • Benchmarks
  • Features

Quickstart

This quickstart gives you a basic understanding of creating a simple endpoint and how to do by using Procyon Framework.

Components

Components are the part of Procyon Framework. Controller, Service, Repository, Initializers, etc. are considered as component.

Register Components

If you have a component like a Controller, you need to notify it to Procyon as Go language doesn't have annotation and similar reflection library like Java. You don't need to be worried about it. The only thing you have to do is to use method core.Register in init, as the following below. It is placed in module procyon-core.

Note that you have to give a function with only one return parameter, which will create a instance of the controller.

config.go

import (
    core "github.com/procyon-projects/procyon-core"
    "github.com/procyon-projects/procyon-test-app/controller"
)

func init() {
    /* Controllers */
    core.Register(controller.NewHelloWorldController)
}

First Controller

The first thing you have to do to have a controller component in Procyon is to implement interface Controller.

The interface Controller looks like the following below. It is placed in module procyon-web.

type Controller interface {
    RegisterHandlers(registry HandlerRegistry)
}

A simple controller will looks like the following below. It might change based on your needs.

type HelloWorldController struct {
}

func NewHelloWorldController() HelloWorldController {
    return HelloWorldController{}
}

func (controller HelloWorldController) RegisterHandlers(registry web.HandlerRegistry) {
    ...
}

func (controller HelloWorldController) HelloWorld(context *web.WebRequestContext) {
    context.Ok().SetBody("Hello World")
}

Registry Handlers

Your handler registrations should be done by using registry which will be passed into the method RegisterHandlers, as you can see the following.

func (controller HelloWorldController) RegisterHandlers(registry web.HandlerRegistry) {
    registry.Register(
        web.Get(controller.HelloWorld, web.Path("/api/helloworld"))
    )
}

You can see the complete code below. It is easy that much to create a controller and register your handlers.

controller.go

type HelloWorldController struct {
}

func NewHelloWorldController() NewHelloWorldController {
    return HelloWorldController{}
}

func (controller HelloWorldController) RegisterHandlers(registry web.HandlerRegistry) {
    registry.Register(
        web.Get(controller.HelloWorld, web.Path("/api/helloworld"))
    )
}

func (controller HelloWorldController) HelloWorld(context *web.WebRequestContext) {
    context.Ok().SetBody("Hello World")
}

Run Application

If you run your application without giving any parameter port, it will start on port 8080 as you can see following.

Image of Console Running

If you want to change the port on which the application start, you can specify parameter --server.port. When you specify the parameter port as 3030 (--server.port=3030), your application will start on port 3030.

Request the endpoint

We assume that you do all steps which needs to be done and have a running application, then it's time to request the endpoint /api/helloworld which we create.

Image of Console Running

If you want to have a good understanding of Procyon framework and work with advanced examples, move on. However, you might want to look into the result of Benchmarks before moving on. Next part, the Benchmark results will be shown.

← IntroductionBenchmarks →
  • Components
  • Register Components
  • First Controller
  • Registry Handlers
  • Run Application
  • Request the endpoint
Procyon
Modules
ProcyonProcyon CoreProcyon ContextProcyon WebProcyon Peas
Community
Discord
More
BlogGitHubStar
Copyright © 2020 Procyon