Getting Started with Fubuki

Getting Started with Fubuki

Getting Started with Fubuki

This guide will help you get started with the Fubuki web framework using the fubuki init command to quickly set up a new project.

Step 1: Install Fubuki

First, you need to install Fubuki and its dependencies. You can do this using pip:

pip install fubuki

Step 2: Initialize a New Project

Use the fubuki init command to create a new project. This command will set up the basic structure for you.

fubuki init project_name

Replace project_name with your desired project name. This will create a directory with the following structure:

project_name/
├── app/
│   ├── controllers/
│   │   └── welcome.py
│   └── routes.py
├── templates/
│   └── index.html
└── main.py

Step 3: Explore the Generated Files

Let’s take a look at the files generated by the fubuki init command.

templates/index.html

This is a simple HTML template that will be rendered by the controller.

It is inspired by the Laravel 5 Welcome Page. Or rather, the structure is almost the same.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Fubuki - Welcome</title>
    <link href="https://fonts.googleapis.com/css?family=Raleway:100,600" rel="stylesheet" type="text/css">
    <style>
        html, body {
            background-color: #fff;
            color: #636b6f;
            font-family: 'Raleway', sans-serif;
            font-weight: 100;
            height: 100vh;
            margin: 0;
        }

        .full-height {
            height: 100vh;
        }

        .flex-center {
            align-items: center;
            display: flex;
            justify-content: center;
        }

        .position-ref {
            position: relative;
        }

        .top-right {
            position: absolute;
            right: 10px;
            top: 18px;
        }

        .content {
            text-align: center;
        }

        .title {
            font-size: 84px;
        }

        .links > a {
            color: #636b6f;
            padding: 0 25px;
            font-size: 12px;
            font-weight: 600;
            letter-spacing: .1rem;
            text-decoration: none;
            text-transform: uppercase;
        }

        .m-b-md {
            margin-bottom: 30px;
        }
    </style>
</head>
<body>
    <div class="flex-center position-ref full-height">
        <div class="content">
            <div class="title m-b-md">
                Fubuki
            </div>

            <div class="links">
                <a href="https://fubuki-dev.github.io/docs">Documentation</a>
                <a href="https://fubuki-dev.github.io/tutorials">Tutorials</a>
                <a href="https://github.com/fubuki-dev/discussion">Community</a>
                <a href="https://github.com/fubuki-dev/fubuki">GitHub</a>
            </div>
        </div>
    </div>
</body>
</html>

app/controllers/welcome.py

This is the default controller created by the fubuki init command.

from fubuki import Controller, get, Request
from fubuki.response import JSONResponse
from fubuki.template import TemplateResponse

class WelcomeController(Controller):
    @get('/')
    async def welcome(request: Request):
        return TemplateResponse("index.html")

app/routes.py

This file is used to register the routes for your application.

from app.controllers.welcome import WelcomeController

def setup_routes(app):
    app.add_route(WelcomeController)

main.py

This is the entry point of your application.

from fubuki import Fubuki
from app.routes import setup_routes

app = Fubuki()

setup_routes(app)

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8000)

Step 4: Run the Application

Navigate to your project directory and run the application using Python.

cd project_name
python main.py

Your application should now be running, and you can access it at http://localhost:8000/.

Summary

Using the fubuki init command, you can quickly set up a new Fubuki project with the necessary structure and a basic controller. From here, you can expand your application by adding more controllers, routes, and templates as needed.