newt
newt is a developer tool. It can set up and run your Newt application during development. newt supports the “config”, “check”, “model”, “generate”, and “run” actions. The “config” command is used when you are starting a Newt Project. It is an interactive command prompting for various choices regarding the application you want to create.
The “check” will analyze the the YAML file and report results of the analyze and as well as validate the YAML syntax.
The “model” is used to manage your data models. It is interactive like “config”.
The “generate” will run the Newt Generator to create the SQL, PostgREST configuration and Handlebars templates. It’ll also update the Newt YAML file’s routes and templates properties as needed for the generated content.
The “run” action will run Newt’s router, template engine and PostgREST for testing and development. This allows you to quick run and stop the services from one command.
If a Newt YAML filename isn’t supplied when you invoke newt the application will look in the current directory for a file with the directory’s name and “.yaml” extension and if that is not found it’ll look for “app.yaml”.
If you are working in the root of a Git repository when you run
“config” you will get a warning about which files should be added to
your .gitignore
.
The following options are supported by newt.
.gitignore
.
newt is configured in a YAML file. What is described below is a summary of YAML syntax use in a Newt project that uses all of the Newt programs.
These are the top level properties in YAML files.
newt model
command.
The applications properties are optional. Some maybe set via command line. See Newt application’s manual page for specific ones. These properties lets you override the default settings of Newt programs.
Routes hosts a list of request descriptions and their data pipelines. This property is only used by Newt router and Newt code generator.
id
description
request [METHOD ][PATH]
GET /items/{item_id}
would make item_id
available in building your service paths in the pipeline. The pattern
takes up a whole path segment so /blog/{year}-{month}-{day}
would not work but /blog/{year}/{month}/{day}
would capture
the individual elements. The Newt router sits closely on top of the Go
1.22 HTTP package route handling. For the details on how Go 1.22 and
above request handlers and patterns form see See https://tip.golang.org/doc/go1.22#enhanced_routing_patterns
and https://pkg.go.dev/net/http#hdr-Patterns for
explanations.
pipeline
debug
newt
service will log verbose
results to standard out for this specific pipeline
A pipeline is a list of web services containing a type, URL, method and content types
service [METHOD ][URL]
.application.environment
. All the elements extracted from
the elements derived from the request path are passed through strings.
These are then used to construct a simple key-value object of variable
names and objects which are then passed through the Mustache template
representing the target service URL.
description
timeout
Models holds a list of individual models used by our data pipelines. The models are describe by a list of HTML5 form elements which intern are described by their attributes.
The model object was inspired by GitHub YAML issue template syntax. It is much simpler and more focus on representing HTML5 webform elements and their attributes directly. HTML5 form elements imply a mapping to SQL data types.
Inputs must map to their HTML 5 form element types. Here is an example of HTML 5 input types.
input[type=data]
would be a date type. This would result in
a date column type in SQL, a date input type in HTML forms and in
formatting other HTML elements for display.
More comple types include
NOTE: The file input type is explicitly NOT supported by Newt at this time. Newt may add additional types in the future through aliasing input with regular expression validation or web components.
newt config app.yaml
and`newt model app.yaml commands.
applications:
router:
port: 8010
htdocs: htdocs
template_engine:
port: 8011
postgres:
namespace: app
port: 5432
dsn: postgres://{PGUSER}:{PGPASSWORD}@localhost:5432/app.yaml
postgrest:
app_path: postgrest
conf_path: postgrest.conf
port: 3000
enviroment:
- PGUSER
- PGPASSWORD
models:
- id: app
description: This is where you would model your application data
elements:
- type: text
id: oid
attributes:
name: oid
title: this is the object identifier for your model
placeholdertext: enter a unique identifier
required: "true"
primary_key: true
- type: text
id: data_attribute
attributes:
name: data_attribute
title: this is an example element in your model
placeholdertext: ex. of placeholder text
required: "true"
routes:
- id: app_create
request: GET /app_create
description: Handle retrieving the webform for app create
pipeline:
- service: POST http://localhost:8011/app_create
description: Display a app for create
- id: app_create
request: POST /app_create
description: Handle form submission for app create
pipeline:
- service: POST http://localhost:3000/rpc/app_create
description: Access PostgREST API for app create
- service: POST http://localhost:8011/app_create_response
description: This is an result template for app create
- id: app_update
request: GET /app_update/{oid}
description: Handle retrieving the webform for app update
pipeline:
- service: GET http://localhost:3000/rpc/app_read/{oid}
description: Retrieve app from PostgREST API before update
- service: POST http://localhost:8011/app_update
description: Display a app for update
- id: app_update
request: POST /app_update
description: Handle form submission for app update
pipeline:
- service: PUT http://localhost:3000/rpc/app_update/{oid}
description: Access PostgREST API for app update
- service: POST http://localhost:8011/app_update_response
description: This is an result template for app update
- id: app_delete
request: GET /app_delete/{oid}
description: Handle retrieving the webform for app delete
pipeline:
- service: GET http://localhost:3000/rpc/app_read/{oid}
description: Retrieve app from PostgREST API before delete
- service: POST http://localhost:8011/app_delete
description: Display a app for delete
- id: app_delete
request: POST /app_delete
description: Handle form submission for app delete
pipeline:
- service: DELETE http://localhost:3000/rpc/app_delete/{oid}
description: Access PostgREST API for app delete
- service: POST http://localhost:8011/app_delete_response
description: This is an result template for app delete
- id: app_read
request: POST /app_read
description: Retrieve object(s) for app read
pipeline:
- service: GET http://localhost:3000/rpc/app_read/{oid}
description: Access PostgREST API for app read
- service: POST http://localhost:8011/app_read
description: This template handles app read
- id: app_list
request: POST /app_list
description: Retrieve object(s) for app list
pipeline:
- service: GET http://localhost:3000/rpc/app_list
description: Access PostgREST API for app list
- service: POST http://localhost:8011/app_list
description: This template handles app list
templates:
- id: app_create
request: /app_create
template: app_create_form.tmpl
description: Display a app for create
- id: app_create
request: /app_create_response
template: app_create_response.tmpl
description: This is an result template for app create
- id: app_update
request: /app_update
template: app_update_form.tmpl
description: Display a app for update
- id: app_update
request: /app_update_response
template: app_update_response.tmpl
description: This is an result template for app update
- id: app_delete
request: /app_delete
template: app_delete_form.tmpl
description: Display a app for delete
- id: app_delete
request: /app_delete_response
template: app_delete_response.tmpl
description: This is an result template for app delete
- id: app_read
request: /app_read
template: app_read.tmpl
description: This template handles app read
- id: app_list
request: /app_list
template: app_list.tmpl
description: This template handles app list
This property is used by Newt Handlebars. It is ignore by Newt router and code generator.
The template objects are used by Newt Handlebars template engine. If you’re not using it you can skip these.
id
request [PATH]
template
partials
.template
.
vocabulary
options
debug
variable numbers must start with a letter, may contain numbers but not spaces or punctuation except the underscore↩︎
variable numbers must start with a letter, may contain numbers but not spaces or punctuation except the underscore↩︎
variable numbers must start with a letter, may contain numbers but not spaces or punctuation except the underscore↩︎