newt
newt OPTIONS ACTION YAML_CONFIG_FILE
newt sets up up and can run your Newt application
during development. newt supports the “init”,
“generate” and “run” actions. The “init” command is used when you are
starting a Newt Project. It will guide you through creating your initial
Newt YAML file and also optionally make additions to your
.gitignore
. “generate” will run the Newt Generator to
create the SQL, PostgREST configuration and Mustache templates based on
the contents of the Newt YAML file. The third action is “run”. It is
used to run your Newt based application. For the applications you have
defined in your Newt YAML_CONFIG_FILE it’s start them up. These include
the Newt Router, Newt Mustache and PostgREST. This allows you to quick
run and stop the services are you craft your Newt YAML file for your
project.
The following options are supported by newt.
.gitignore
file too.
newt is configured in a YAML file. What is described below is the complete YAML syntax use in a Newt project that uses all of the Newt programs.
These are the top level properties in YAML files.
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 by Newt code generator and the Newt router. Models defines a superset of the GitHub YAML issue template syntax (abbr: GHYITS).
The model object is based largely on GitHub YAML issue template syntax with a couple extra properties that are Newt enhancements.
The following properties are based on the GitHub YAML issue template syntax3 (abbr: GHYITS)
This is based on GitHub YAML issue template (abbr: GHYITS) input types5.
Both the routes and models may contain input types. The types supported in Newt are based on the types found in the GHYITS for scheme7. They include
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.
Newt may add additional types in the future.
applications:
newtgenerator:
namespace: people # E.g. "people" Namespace to use generating Postgres SQL
newtrouter:
port: 8011 # Port number for Newt Router
htdocs: htdocs # Path to static content directory if required
newtmustache:
port: 8012 # Port number for Newt Mustache
#options:
# name value pairs used for aliasing strings in routes, models, and templates
environment:
- DB_USER
- DB_PASSWORD
- DB_HOST
models:
- id: people
name: People Profiles
description: |
This models a curated set of profiles of colleagues body:
- id: people_id
type: input
attributes:
label: A unique person id, no spaces, alpha numeric
placeholder: ex. jane-do-007
validations:
required: true
- id: display_name
type: input
attributes:
label: (optional) A person display name
placeholder: ex. J. Doe, journalist
- id: family_name
type: input
attributes:
label: (required) A person's family name or singular when only one name exists
placeholder: ex. Doe
validations:
required: true
- id: given_name
type: input
attributes:
label: (optional, encouraged) A person's given name
placeholder: ex. Jane
- id: orcid
type: input
attributes:
label: (optional) A person's ORCID identifier
placeholder: ex. 0000-0000-0000-0000
validations:
pattern: "[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]"
- id: ror
type: input
attributes:
label: (optional) A person's ROR identifying their affiliation
- id: email
type: "input[type=email]"
attributes:
label: (optional) A person public email address
- id: website
type: "input[type=url]"
attributes:
label: (optional) A person's public website
placeholder: ex. https://jane.doe.example.org
routes:
- id: create_person
description: Create new person profile
request: POST /person
pipeline:
- description: This will generate a new user in the database
service: POST "https://{{DB_USER}}@{{DB_HOST}}:3000/rpc/people"
content_type: application/json
- description: |
This sends the results of creating a person to the template engine service: POST http://localhost:3032/people_update_result.tmpl
content_type: application/json
- id: read_person
description: Update a person's profile
request: "GET /person/{{people.people_id}}"
pipeline:
- description: Retrieve a person's profile
service: POST "https://{{DB_USER}}@{{DB_HOST}}:3000/person/{{people.people_id}}"
content_type: application/json
- description: |
Render a person's profile service: POST http://localhost:3032/profile.tmpl
content_type: application/json
- id: update_person
description: Update person's profile
request: "PUT /person/{{people.people_id}}"
pipeline:
- description: This will update a person record in the database
service: PUT "https://{{DB_USER}}@{{DB_HOST}}:3000/rpc/people"
content_type: application/json
- description: |
This sends the results of updating a person to the template engine service: POST http://localhost:3032/people_update_result.tmpl
content_type: application/json
- id: delete_person
description: Remove person's profile
request: "DELETE /person/{{people.people_id}}"
pipeline:
- description: Remove the person for the database
service: DELETE "https://{{DB_USER}}@{{DB_HOST}}:3000/people/{{people.people_id}}"
content_type: application/json
- description: Displace the result of what happened in the removal
service: POST http://localhost:3032/removed_person.tmpl
- id: list_people
description: List people profiles available
request: GET /people
pipeline:
- description: Retrieve a list of all people profiles available
service: GET https://{{DB_HOST}}@{{DB_HOST}}:3000/people
content_type: application/json
- description: format a browsable people list linking to individual profiles
service: POST http://localhost:3030/list_people.tmpl
content_type: application/json
This property is used by Newt Mustache. It is ignore by Newt router and code generator.
The template objects are used by Newt Mustache template engine. If you’re not using it you can skip these.
request [METHOD ][PATH]
template
partials
.template
.
options
debug
Example of newtmustache YAML:
applications:
newtmustache:
port: 8012
templates:
- request: GET /hello/{name}
template: testdata/simple.mustache
- request: GET /hello
template: testdata/simple.mustache
options:
name: Universe
- request: GET /hi/{name}
template: testdata/hithere.html
partials:
- testdata/name.mustache
debug: true
- request: GET /hi
template: testdata/hithere.html
partials:
- testdata/name.mustache
options:
name: Universe
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↩︎
See https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-issue-forms,↩︎
See https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-issue-forms,↩︎
See https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-githubs-form-schema↩︎
variable numbers must start with a letter, may contain numbers but not spaces or punctuation except the underscore↩︎
See https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-githubs-form-schema↩︎