Skip to content

Commit

Permalink
Add to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlieJKendall committed Apr 14, 2020
1 parent aa4832c commit 2ef2798
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 7 deletions.
6 changes: 5 additions & 1 deletion docs/data-providers.md
@@ -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.
58 changes: 56 additions & 2 deletions docs/global-configuration.md
@@ -1,3 +1,57 @@
# 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"))
}
```

## Configuration Options

### AllowedVerbs

Default: `HttpVerbs.All`

The HTTP verbs that every resource allows. This can be overridden at the resource-level if required.
25 changes: 23 additions & 2 deletions docs/model-configuration.md
@@ -1,3 +1,24 @@
# Snoozle
Model configuration is applied at the REST resource (model) level. This page details core configuratoin, 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.
48 changes: 46 additions & 2 deletions docs/property-configuration.md
@@ -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());
```

0 comments on commit 2ef2798

Please sign in to comment.