Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa4832c
commit 391db66
Showing
7 changed files
with
160 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# Data Providers | ||
|
||
!!! warning "Docs under construction - please bear with us" | ||
The following data providers are officially supported, and can be downloaded as NuGet packages: | ||
|
||
- [In-Memory](https://github.com/CharlieJKendall/Snoozle) Data is stored in-memory with initial data provided via a JSON file. This is included with the main Snoozle package. | ||
- [Microsoft SQL Server](https://github.com/CharlieJKendall/Snoozle.SqlServer) Data is stored and retrieved from a SQL Server database. | ||
- [Read-only JSON](https://github.com/CharlieJKendall/Snoozle.ReadOnlyJson) Data is provided from a JSON file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Snoozle | ||
#### ConnectionString | ||
|
||
!!! warning "Docs under construction - please bear with us" | ||
The connection string to use to connect to the SQL Server instance your data is stored in. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,55 @@ | ||
# Snoozle | ||
Global configuration is applied at the application level. This page details core configuratoin, however different data providers may add extra global configuration values. | ||
|
||
!!! warning "Docs under construction - please bear with us" | ||
**Configuring in code** | ||
|
||
Global configuration can be set in code from the relevant `AddSnoozle()` method in the `Startup.cs` file. This is generally used only for development convenience- production applications should define configuration in a separate configuration file (see below). | ||
|
||
``` cs | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
services | ||
.AddMvc() | ||
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2) | ||
.AddSnoozleInMemory(options => | ||
{ | ||
options.AllowedVerbs = HttpVerbs.All; | ||
}); | ||
} | ||
``` | ||
|
||
**Configuring with appSettings.json** | ||
|
||
Global configuration can be set in the appSettings.json file under a 'Snoozle' root entry: | ||
|
||
``` json | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*", | ||
"Snoozle": { | ||
"AllowedVerbs": "post, get, put, delete" | ||
} | ||
} | ||
|
||
``` | ||
|
||
This is then passed to the relevent `AddSnoozle()` method in the `Startup.cs` file. | ||
|
||
``` cs | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
services | ||
.AddMvc() | ||
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2) | ||
.AddSnoozleInMemory(Configuration.GetSection("Snoozle")) | ||
} | ||
``` | ||
|
||
#### AllowedVerbs | ||
|
||
Default: `HttpVerbs.All` | ||
|
||
The HTTP verbs that every resource allows. This can be overridden at the resource-level if required. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Snoozle | ||
#### HasTableName | ||
|
||
!!! warning "Docs under construction - please bear with us" | ||
Specifies the table name for the data represented by the given resource. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,24 @@ | ||
# Snoozle | ||
Model configuration is applied at the REST resource (model) level. This page details core configuration, however different data providers may add extra model configuration values. | ||
|
||
!!! warning "Docs under construction - please bear with us" | ||
These are configured via the `IModelConfigurationBuilder` in the `Configure()` method of a resource configuration: | ||
|
||
``` cs | ||
public override void Configure() | ||
{ | ||
ConfigurationForModel() | ||
.HasRoute("new-api-route") | ||
.HasAllowedHttpVerbs(HttpVerbs.Put | HttpVerbs.Post); | ||
} | ||
``` | ||
|
||
#### HasRoute | ||
|
||
Default: The name of the resource with the character `s` appended | ||
|
||
Sets the route that the resource can be accessed at. For example, `HasRoute("another-route")` would expose the resource at `https://baseuri/api/another-route`. | ||
|
||
#### HasAllowedHttpVerbs | ||
|
||
Default: The same as the value set in the global configuration | ||
|
||
The HTTP verbs that every resource allows. This overrides the globally set value. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,29 @@ | ||
# Snoozle | ||
#### HasDqlDbType | ||
|
||
!!! warning "Docs under construction - please bear with us" | ||
Sets the SqlDbType that the proprety maps to for cases where the default mapping is insufficient. Generally used for date and time mappings. | ||
|
||
**Default Mappings** | ||
|
||
| .NET Type | SqlDbType Enum | | ||
| ----- | ----- | | ||
| `long` | `SqlDbType.BigInt` | | ||
| `byte[]` | `SqlDbType.VarBinary` | | ||
| `bool` | `SqlDbType.Bit` | | ||
| `string` | `SqlDbType.NVarChar` | | ||
| `DateTime` | `SqlDbType.DateTime` | | ||
| `DateTimeOffset` | `SqlDbType.DateTimeOffset` | | ||
| `decimal` | `SqlDbType.Decimal` | | ||
| `double` | `SqlDbType.Float` | | ||
| `float` | `SqlDbType.Float` | | ||
| `int` | `SqlDbType.Int` | | ||
| `short` | `SqlDbType.SmallInt` | | ||
| `TimeSpan` | `SqlDbType.Time` | | ||
| `Guid` | `SqlDbType.UniqueIdentifier` | | ||
| `byte` | `SqlDbType.TinyInt` | | ||
| `char` | `SqlDbType.Char` | | ||
|
||
#### HasColumnName | ||
|
||
Default: The name of the property | ||
|
||
Sets the name of the column that maps to the property. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,47 @@ | ||
# Snoozle | ||
Property configuration is applied at the REST resource property level. This page details core configuratoin, however different data providers may add extra property configuration values. | ||
|
||
!!! warning "Docs under construction - please bear with us" | ||
These are configured via the `IPropertyConfigurationBuilder` in the `Configure()` method of a resource configuration: | ||
|
||
``` cs | ||
public override void Configure() | ||
{ | ||
ConfigurationForProperty(x => x.Id) | ||
.HasComputedValue(HttpVerbs.POST).RandomlyGeneratedGuid() | ||
.IsPrimaryIdentifier(); | ||
} | ||
``` | ||
|
||
#### IsReadOnly | ||
|
||
Default: False | ||
|
||
Whether the data is returned on `GET` requests or not. This is generally used for metadata such as timestamps or trace identifiers. | ||
|
||
#### IsPrimaryIdentifier | ||
|
||
Default: False unless convention criteria are satisfied | ||
|
||
!!! tip "Convention" | ||
A property with the name `Id` or `<resource_class_name>Id` will be set as the primary identifier by convention if no other property is explicitly set. | ||
|
||
Defines which property defines the identity of a resource. This will be used to access specific resources in the URL. | ||
|
||
#### HasComputedValue | ||
|
||
Specifies that the value of the property is automatically computed and not defined in the payload of the HTTP request. This method returns a builder object that is used to define the value of this property: | ||
|
||
**DateTimeNow** | ||
|
||
Sets the value of the property to the value of `DateTime.Now` at request-time. | ||
|
||
**DateTimeUtcNow** | ||
|
||
Sets the value of the property to the value of `DateTime.UtcNow` at request-time. | ||
|
||
**Custom** | ||
|
||
Sets the value of the property to that specified by the `Func<TProperty>`. For example, the following would set the value to a random GUID for a property with type `Guid` on POST requests: | ||
|
||
``` cs | ||
ConfigurationForProperty(x => x.Id).HasComputedValue(HttpVerbs.POST).Custom(x => Guid.NewGuid()); | ||
``` |