package
0.9.0
Repository: https://github.com/viant/datly.git
Documentation: pkg.go.dev

# README

Resource

Router provides REST Api layer. Internally it uses the Views in order to communicate with database and add extra layer to handle http requests in order to read and filter data. It can be configured programmatically or by reading external configuration from yaml file.

In the yaml file, following sections can be configured:

SectionDescriptionTypeRequired
Routesconfiguration for specific route[]Routetrue
Resourceconfiguration of Views, Connectors and Parameters shared across the RoutesResourcefalse
CompressionCompression configuraion that will be used for all Routes unless Route Compression is configuredCompressionfalse
CorsCors configuraion that will be used for all Routes unless Route Cors is configuredCorsfalse
APIURIstringtrue
SourceURLstringfalse
With[]stringfalse

Cors

In order to enable the web browser cross-origin requests, the Cors need to be configured. If any of the section is not specified, corresponding Http header will not be added to the Cors preflight request:

SectionDescriptionTypeRequired
AllowCredentialsAccess-Control-Allow-Credentials header valueboolfalse
AllowHeadersAccess-Control-Allow-Headers header value[]stringfalse
AllowMethodsAccess-Control-Allow-Methods header value[]stringfalse
AllowOriginsAccess-Control-Allow-Origin header value[]stringfalse
ExposeHeadersAccess-Control-Expose-Headers header value[]stringfalse
MaxAgeAccess-Control-Max-Age header valueintfalse

Compression

In order to compress data if response exceed given size, Compression configuration need to be specified:

SectionDescriptionTypeRequiredDefault value
MinSizeKbMinimum size in KB after when response should be compressedintfalse0

Route

Route configures specific URL handler for given http method. The Compression and Cors can be configured on the router level, but can also be overridden on the Route level. In the Route section, following properties can be configured.

SectionDescriptionTypeRequiredDefault value
URIUrl pattern that Requests will be matched with. The path variables have to be put between brackets i.e. /users/{userId}stringtrue""
ViewView definition used to fetch data from databaseViewtruenull
MethodHttp method used to match http requestsenum: GET, POSTtrue""
ServiceThe service type used to handle the requests.enum: ReaderfalseGET -> Reader, Post -> ""
CorsCors configuration specific for the RouteCorsfalsenull
CardinalityIndicates whether single object should be returned or the array of objects.enum: ONE, MANYfalseMANY
CaseFormatConfigures the output JSON field names format.enum: CaseFormatfalseuppercamel
OmitEmptyRemoves zero values from the output. Examples of removable values: 0, "", false, [], nullbooleanfalsefalse
StyleIndicates whether response body should be wrapped with status code and error message (Comprehensive) or just returned as isenum: Basic, ComprehensivefalseBasic
FieldResponseBody field for Comprehensive Stylestring in the UperCamelCase formatfalseResponseBody
NamespaceMapping between Selector prefix into the View namestring -> string map / pairsfalsenull
VisitorInterceptor that can execute some logic before or/and after data was fetched from database. In order to use Visitors, Visitor need to be created programmatically and passed to the ConfigurationVisitorfalsenull
ViewView configuration used to fetch data from databaseViewtruenull
CompressionRoute specific Compression configurationCompressionfalsenull
CacheRoute specific Cache configurationCachefalsenull
ExcludeFields that will be excluded from response.Field paths in format: CammelCase.CammelCase.OutputCase, i.e. - Employees.Departments.idfalse[]string{}
NormalizeExcludeIn order to use Excluded path using only CammelCase NormalizeExclude needs to be set to false.boolfalsetrue

Cache

Cache caches the database result for the main view specified on the Route level. It uses the Selectors to produce entry key. The cache key is produced using the Selectors. If two http requests produces the same Selectors, and one happen after the other in time shorter than specified, the data will be read from the cache:

SectionDescriptionTypeRequired
TimeToLiveMsCache entry time after when entry will be invalidatedinttrue
StorageURLURL of the stored cache entriesstringtrue

Visitor

Visitor intercepts regular reader flow. Visitor executes regular golang code so in order to use them they have to be registered before Resource is initialized. It can implement following interfaces:

  • BeforeFetch - executes before data is fetched from the database.
BeforeFetch(response http.ResponseWriter, request *http.Request) (responseClosed bool, err error)
  • AfterFetch - executes after data is fetched from the database.
AfterFetch(data interface{}, response http.ResponseWriter, request *http.Request) (responseClosed bool, err error)
SectionDescriptionTypeRequired
NameVisitor name, has to match visitors map key provided programmaticallystringtrue

Examples

For examples see test cases

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Constants

No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author

# Type aliases

ContextHandler http handler with context.
No description provided by the author
No description provided by the author