Document HTTP Service

There is possibility to expose the storage via HTTP as is. Be careful, it provide powerful mechanism for quick start but to build clear and understandable RESTful API better create own HTTP services.

Configuring Document HTTP Service

1. Install InfinniPlatform.DocumentStorage.HttpService package:

dotnet add package InfinniPlatform.DocumentStorage.HttpService \
    -s https://www.myget.org/F/infinniplatform/

2. Call AddDocumentStorageHttpService() in ConfigureServices():

 using System;

 using InfinniPlatform.AspNetCore;

 using Microsoft.Extensions.DependencyInjection;

 public class Startup
 {
     public IServiceProvider ConfigureServices(IServiceCollection services)
     {
         services.AddDocumentStorageHttpService();

         // ...

         return services.BuildProvider();
     }

     // ...
 }

3. Register in IoC-container the document HTTP service:

builder.RegisterDocumentHttpService<MyDocument>();

4. Run application and browse to http://localhost:5000/documents/MyDocument/

Interception of Document HTTP Service

The document HTTP service provides default behavior which may be a little different than what you want. In this case you can use interceptor of the document HTTP service. Implement IDocumentStorageInterceptor<TDocument> (typed context) or IDocumentStorageInterceptor (dynamic context) and register the implementation in IoC-container.

Document HTTP Service API

GET /documents/(string: documentType)/(string: id)

Returns the document of the specified type and with given identifier.

Parameters:
  • documentType (string) – The document type name.
  • id (string) – The document unique identifier.
Response Headers:
 
Status Codes:
GET /documents/(string: documentType)/

Returns documents of the specified type.

Parameters:
  • documentType (string) – The document type name.
Query Parameters:
 
  • search (string) – Optional. The text for full text search.
  • filter (string) – Optional. The filter query.
  • select (string) – Optional. The select query.
  • order (string) – Optional. The order query.
  • count (boolean) – Optional. By default - false. The flag whether to return the number of documents.
  • skip (int) – Optional. By default - 0. The number of documents to skip before returning the remaining elements.
  • take (int) – Optional. By default - 10, maximum - 1000. The number of documents to return.
Response Headers:
 
Status Codes:
POST /documents/(string: documentType)/

Creates or updates specified document.

Parameters:
  • documentType (string) – The document type name.
Form Parameters:
 
  • body – The document and optionally the document attachments (files).
Request Headers:
 
Response Headers:
 
Status Codes:
DELETE /documents/(string: documentType)/(string: id)

Deletes the document of the specified type and with given identifier.

Parameters:
  • documentType (string) – The document type name.
  • id (string) – The document unique identifier.
Response Headers:
 
Status Codes:
DELETE /documents/(string: documentType)/

Deletes documents of the specified type.

Parameters:
  • documentType (string) – The document type name.
Query Parameters:
 
Response Headers:
 
Status Codes:

Filter Query

The filter query is a string with contains a filter expression:

func(args)

where func - the filter function name, args - the function arguments.

There are a lot of function, most of them accepts a document property name as the first parameter and an appropriate value as the second parameter which is used to compare with the property. Some functions can accept other functions as arguments such as composing function - and and or, other functions can have no arguments, have one or any amount. Below the filter query functions are presented.

Logical Query Functions

not(filter)

The logical negation of the specified expression.

Example:

not(eq('status', 'published'))
Arguments:
  • filter – The filter query.
and(filters)

The logical conjunction of the specified expression.

Example:

and(eq('status', 'published'), eq('author', 'John Smith'))
Arguments:
  • filters – The list of filter queries separated by comma.
or(filters)

The logical disjunction of the specified expression.

and(eq('status', 'published'), eq('status', 'signed'))
Arguments:
  • filters – The list of filter queries separated by comma.

Element Query Functions

exists(field[, exists = true])

When exists is true, matches the documents that contain the field, including documents where the field value is null; if exists is false, the query returns only the documents that do not contain the field.

Arguments:
  • field (string) – The document field name.
  • exists (boolean) – The flag of existings.
type(field, valueType)

Selects the documents where the value of the field is an instance of the specified type. Querying by data type is useful when dealing with highly unstructured data where data types are not predictable.

Available Types:

  • Boolean
  • Int32
  • Int64
  • Double
  • String
  • DateTime
  • Timestamp
  • Binary
  • Object
  • Array

Example:

type('zipCode', 'String')
Arguments:
  • field (string) – The document field name.
  • valueType (string) – The document field type.

Comparison Query Functions

in(field, values)

Selects the documents where the value of a field equals any value in the specified array.

Example:

in('tags', '.net', 'asp.net', 'c#')
Arguments:
  • field (string) – The document field name.
  • values – The field values.
notIn(field, values)

Selects the documents where the field value is not in the specified array or the field does not exist.

Example:

notIn('tags', '.net', 'asp.net', 'c#')
Arguments:
  • field (string) – The document field name.
  • values – The field values.
eq(field, value)

Specifies equality condition, matches documents where the value of a field equals the specified value.

Example:

eq('status', 'published')
Arguments:
  • field (string) – The document field name.
  • value – The field value.
notEq(field, value)

Selects the documents where the value of the field is not equal to the specified value. This includes documents that do not contain the field.

Example:

notEq('status', 'published')
Arguments:
  • field (string) – The document field name.
  • value – The field value.
gt(field, value)

Selects those documents where the value of the field is greater than the specified value.

Example:

gt('price', 9.99)
Arguments:
  • field (string) – The document field name.
  • value – The field value.
gte(field, value)

Selects the documents where the value of the field is greater than or equal to a specified value.

Example:

gte('price', 9.99)
Arguments:
  • field (string) – The document field name.
  • value – The field value.
lt(field, value)

Selects the documents where the value of the field is less than the specified value.

Example:

lt('price', 9.99)
Arguments:
  • field (string) – The document field name.
  • value – The field value.
lte(field, value)

Selects the documents where the value of the field is less than or equal to the specified value.

Example:

lte('price', 9.99)
Arguments:
  • field (string) – The document field name.
  • value – The field value.
regex(field, pattern)

Selects documents where the value of the field matches a specified regular expression.

Example:

regex('phone', '^+123')
Arguments:
  • field (string) – The document field name.
  • pattern (string) – The regular expression.
startsWith(field, value[, ignoreCase = true])

Selects documents where the value of the field starts with a specified substring.

Example:

startsWith('phone', '+123')
Arguments:
  • field (string) – The document field name.
  • value (string) – The substring to matching.
  • ignoreCase (boolean) – The flag of ignoring case.
endsWith(field, value[, ignoreCase = true])

Selects documents where the value of the field ends with a specified substring.

Example:

endsWith('phone', '789')
Arguments:
  • field (string) – The document field name.
  • value (string) – The substring to matching.
  • ignoreCase (boolean) – The flag of ignoring case.
contains(field, value[, ignoreCase = true])

Selects documents where the value of the field contains a specified substring.

Example:

contains('phone', '456')
Arguments:
  • field (string) – The document field name.
  • value (string) – The substring to matching.
  • ignoreCase (boolean) – The flag of ignoring case.

Array Query Functions

match(arrayField, filter)

Selects documents where the value of the field is an array which contains elements that satisfy the specified filter.

Example:

match('addresses', eq('street', 'Broadway'))
Arguments:
  • arrayField (string) – The document field which contains an array.
  • filter – The filter query.
all(arrayField, elements)

Selects the documents where the value of a field is an array that contains all the specified elements.

Example:

all('tags', '.net', 'asp.net', 'c#')
Arguments:
  • arrayField (string) – The document field which contains an array.
  • elements – The list of elements to matching.
anyIn(arrayField, elements)

Selects the documents where the value of a field is an array that contains at least one of the specified elements.

Example:

anyIn('tags', '.net', 'asp.net', 'c#')
Arguments:
  • arrayField (string) – The document field which contains an array.
  • elements – The list of elements to matching.
anyNotIn(arrayField, elements)

Selects the documents where the value of a field is an array that does not contains the specified elements.

Example:

anyNotIn('tags', '.net', 'asp.net', 'c#')
Arguments:
  • arrayField (string) – The document field which contains an array.
  • elements – The list of elements to matching.
anyEq(arrayField, element)

Selects the documents where the value of a field is an array that contains at least one element that equals the specified.

Example:

anyEq('tags', '.net')
Arguments:
  • arrayField (string) – The document field which contains an array.
  • element – The element to matching.
anyNotEq(arrayField, element)

Selects the documents where the value of a field is an array that contains at least one element that does not equal the specified.

Example:

anyNotEq('tags', '.net')
Arguments:
  • arrayField (string) – The document field which contains an array.
  • element – The element to matching.
anyGt(arrayField, element)

Selects the documents where the value of a field is an array that contains at least one element that is greater than the specified.

Example:

anyGt('scores', 42)
Arguments:
  • arrayField (string) – The document field which contains an array.
  • element – The element to matching.
anyGte(arrayField, element)

Selects the documents where the value of a field is an array that contains at least one element that is greater than or equal to the specified.

Example:

anyGte('scores', 42)
Arguments:
  • arrayField (string) – The document field which contains an array.
  • element – The element to matching.
anyLt(arrayField, element)

Selects the documents where the value of a field is an array that contains at least one element that is less than the specified.

Example:

anyLt('scores', 42)
Arguments:
  • arrayField (string) – The document field which contains an array.
  • element – The element to matching.
anyLte(arrayField, element)

Selects the documents where the value of a field is an array that contains at least one element that is less than or equal to the specified.

Example:

anyLte('scores', 42)
Arguments:
  • arrayField (string) – The document field which contains an array.
  • element – The element to matching.
sizeEq(arrayField, size)

Selects the documents where the value of a field is an array which size equals the specified.

Example:

sizeEq('scores', 42)
Arguments:
  • arrayField (string) – The document field which contains an array.
  • size (int) – The element to matching.
sizeGt(arrayField, size)

Selects the documents where the value of a field is an array which size is greater than the specified.

Example:

sizeGt('scores', 42)
Arguments:
  • arrayField (string) – The document field which contains an array.
  • size (int) – The element to matching.
sizeGte(arrayField, size)

Selects the documents where the value of a field is an array which size is greater than or equal to the specified.

Example:

sizeGte('scores', 42)
Arguments:
  • arrayField (string) – The document field which contains an array.
  • size (int) – The element to matching.
sizeLt(arrayField, size)

Selects the documents where the value of a field is an array which size is less than the specified.

Example:

sizeLt('scores', 42)
Arguments:
  • arrayField (string) – The document field which contains an array.
  • size (int) – The element to matching.
sizeLte(arrayField, size)

Selects the documents where the value of a field is an array which size is less than or equal to the specified.

Example:

sizeLte('scores', 42)
Arguments:
  • arrayField (string) – The document field which contains an array.
  • size (int) – The element to matching.

Constant Query Functions

date(value)

Specifies a date and time constant using ISO 8601 format.

Example:

date('2017-06-21')
Arguments:
  • value (string) – The date and time in ISO 8601 format.

Select Query

The select query allows to request the only specified fields of the document or vice versa exclude specified fields of the document. The select query is a string with contains a list of expressions separated by comma:

func(args), func(args), ...

where func - the select function name, args - the function arguments.

Below the select query functions are presented.

include(field)

Specifies that the specified field should be included in the response.

Example:

include('addresses')
Arguments:
  • field (string) – The document field name.
exclude(field)

Specifies that the specified field should be excluded from the response.

Example:

exclude('addresses')
Arguments:
  • field (string) – The document field name.

Order Query

The order query specifies the order in which the query returns matching documents. The order query is a string with contains a list of expressions separated by comma:

func(args), func(args), ...

where func - the order function name, args - the function arguments.

Below the order query functions are presented.

asc(field)

Specifies an ascending sort for the specified field.

Example:

asc('creationDate')
Arguments:
  • field (string) – The document field name.
desc(field)

Specifies an descending sort for the specified field.

Example:

desc('creationDate')
Arguments:
  • field (string) – The document field name.