VOOZH about

URL: https://www.nuget.org/packages/RestDb/

⇱ NuGet Gallery | RestDb 2.0.3




👁 Image
RestDb 2.0.3

dotnet add package RestDb --version 2.0.3
 
 
NuGet\Install-Package RestDb -Version 2.0.3
 
 
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RestDb" Version="2.0.3" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RestDb" Version="2.0.3" />
 
Directory.Packages.props
<PackageReference Include="RestDb" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RestDb --version 2.0.3
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: RestDb, 2.0.3"
 
 
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package RestDb@2.0.3
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RestDb&version=2.0.3
 
Install as a Cake Addin
#tool nuget:?package=RestDb&version=2.0.3
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

RestDb

RESTful HTTP/HTTPS server for Microsoft SQL Server, MySQL, and PostgreSQL database tables written in C#.

Description

RestDb spawns a RESTful HTTP/HTTPS server that exposes a series of APIs allowing you to perform SELECT, INSERT, UPDATE, DELETE, TRUNCATE, and DROP against tables in Microsoft SQL Server, MySQL, PostgreSQL, and Sqlite.

New in v2.0.2

  • Dependency update to silence dependabot

Important Notes

  • If you specify a listener other than localhost or 127.0.0.1, you may have to run with elevated privileges.
  • The HTTP HOST header MUST match the listener hostname, otherwise you'll get Bad Request errors back.
  • By default, access to RestDb is UNAUTHENTICATED. Configure system.json with API keys to enable authentication, and set the RequireAuthentication value to true.

Execution

> cd RestDb\bin\debug\netcoreapp2.2
> dotnet RestDb.dll

Setup

  1. Start RestDb as described above. You will be guided through a setup process to connect to your databases. Alternatively, you can start with Sqlite which requires no database setup.
 _ _ _
 _ __ ___ ___| |_ __| | |__
 | '__/ _ \/ __| __/ _ | _ \
 | | | __/\__ \ || (_| | |_) |
 |_| \___||___/\__\__,_|_.__/


Listening for requests on http://localhost:8000

  1. Verify Connectivity

Point your browser to http://localhost:8000. You should see a default webpage for RestDb.

Simple Examples

List databases

GET http://localhost:8000/_databases

Resp:
200/OK
[
 "test"
]

Create a Table

POST http://localhost:8000/test
Data: 
{
 "Name": "person",
 "PrimaryKey": "person_id",
 "Columns": [
 {
 "Name": "person_id",
 "Type": "int",
 "Nullable": false
 },
 {
 "Name": "first_name",
 "Type": "nvarchar",
 "MaxLength": 32,
 "Nullable": false
 },
 {
 "Name": "last_name",
 "Type": "nvarchar",
 "MaxLength": 32,
 "Nullable": true
 },
 {
 "Name": "age",
 "Type": "int",
 "Nullable": false
 },
 {
 "Name": "created",
 "Type": "datetime",
 "Nullable": true
 }
 ]
}

Resp:
201/Created

Retrieve a Database

GET http://localhost:8000/test

Resp:
200/OK
{
 "Name": "test",
 "Type": "mssql",
 "Hostname": "localhost",
 "Port": 1433,
 "Instance": "sqlexpress",
 "Debug": false,
 "TableNames": [
 "person"
 ]
}

Describe a Table

GET http://localhost:8000/test/person?_describe

Resp:
200/OK
{
 "Name": "person",
 "PrimaryKey": "person_id",
 "Columns": [
 {
 "Name": "person_id",
 "Type": "int",
 "Nullable": false
 },
 {
 "Name": "first_name",
 "Type": "nvarchar",
 "MaxLength": 32,
 "Nullable": false
 },
 {
 "Name": "last_name",
 "Type": "nvarchar",
 "MaxLength": 32,
 "Nullable": true
 },
 {
 "Name": "age",
 "Type": "int",
 "Nullable": false
 },
 {
 "Name": "created",
 "Type": "datetime",
 "Nullable": true
 }
 ]
}

Create an Object

Be sure to use timestamps appropriate to your database type, for instance:

  • MsSql: MM/dd/yyyy HH:mm:ss
  • MySql: yyyy-MM-dd HH:mm:ss
  • PgSql: MM/dd/yyyy HH:mm:ss
  • Sqlite: yyyy-MM-dd HH:mm:ss
POST http://localhost:8000/test/person
Data: { first_name: 'joel', last_name: 'christner', age: 40, created: '05/03/2017' }

Resp:
201/Created
{
 "person_id": 1,
 "first_name": "joel",
 "last_name": "christner",
 "age": 40,
 "created": "05/03/2017 00:00:00"
}

Create Multiple Objects

To create multiple objects, send a JSON array containing a series of dictionaries appropriate for the specified table.

POST http://localhost:8080/test/person?_multiple
Data: [ { first_name: 'person1', last_name: 'last', age: 50, created '5/1/2017' }, ... ]

Resp:
201/Created

Retrieve Objects

You can retrieve all of a table's contents, retrieve by a specific ID, and filter by key-value pairs (using the querystring).

GET http://localhost:8000/test/person 
GET http://localhost:8000/test/person/1
GET http://localhost:8000/test/person?first_name=joel 

Resp:
200/OK
[
 {
 "person_id": 1,
 "first_name": "joel",
 "last_name": "christner",
 "age": 18,
 "created": "1990-04-23T00:00:00Z"
 }, 
 { ... }
]

Retrieve Objects with Pagination

You can retrieve results and use pagination to return only a subset. Include _index, _max, _order, and _order_by in the querystring.

  • _index is the starting index
  • _max is the maximum number of results to retrieve
  • _order must be either asc (ascending) or desc (descending).
  • _order_by is one or more column names in a comma-separated list.

By default, SELECT requests are ordered ASCENDING by the table's primary key.

GET http://localhost:8000/test/person?_max=1&_index=1&_order=asc&_order_by=person_id,first_name

Resp:
200/OK
[
 {
 "__row_num__": 1,
 "person_id": 1,
 "first_name": "joel",
 "last_name": "christner",
 "age": 40,
 "created": "05/03/2017 00:00:00"
 },
 { ... }
]

Update an Object

Supply the ID in the URL and include the key-value pairs to change in the request body.

PUT http://localhost:8000/test/person/1
Data: { age: 18 }

Resp:
200/OK
{
 "person_id": 1,
 "first_name": "joel",
 "last_name": "christner",
 "age": 18,
 "created": "05/03/2017 00:00:00"
}

Search for an Object

Uses the Expression syntax found in DatabaseWrapper (refer to examples here: https://github.com/jchristn/DatabaseWrapper). These can be nested in a hierarchical manner.

PUT http://localhost:8000/test/person
Data: 
{
 "Left": "person_id",
 "Operator": "GreaterThan",
 "Right": 0
}

Resp:
200/OK
[
 {
 "person_id": 1,
 "first_name": "joel",
 "last_name": "christner",
 "age": 18,
 "created": "05/03/2017 00:00:00"
 }
]

Delete an Object

DELETE http://localhost:8000/test/person/1

Resp: 
204/Deleted

Truncating a Table

DELETE http://localhost:8000/test/person?_truncate

Resp: 
204/Deleted

Dropping a Table

DELETE http://localhost:8000/test/person?_drop

Resp:
204/Deleted

Executing a Raw Query

POST http://localhost:8000/test?raw
Data:
SELECT * FROM person;

Resp:
200/OK 
[
 {
 "person_id": 1,
 "first_name": "joel",
 "last_name": "christner",
 "age": 18,
 "created": "05/03/2017 00:00:00"
 }
]

Enabling Authentication

To enable authentication, set Server.RequireAuthentication to true and specify an API key header in Server.ApiKeyHeader in the System.Json file. Then, add a section called ApiKeys with each of the keys you wish to allow or disallow. An example with one API key is below.

{
 "Version": "1.1.0",
 "Server": {
 "ListenerHostname": "localhost",
 "ListenerPort": 8000,
 "Ssl": false,
 "Debug": false,
 "RequireAuthentication": true,
 "ApiKeyHeader": "x-api-key"
 },
 "Logging": { 
 "ServerIp": "127.0.0.1",
 "ServerPort": 514,
 "MinimumLevel": 1,
 "LogHttpRequests": false,
 "LogHttpResponses": false,
 "ConsoleLogging": true
 },
 "Databases": [
 {
 "Name": "test",
 "Type": "MsSql",
 "Hostname": "localhost",
 "Port": 1433,
 "Instance": "SQLEXPRESS",
 "Username": "root",
 "Password": "password",
 "Debug": false
 }
 ],
 "ApiKeys": [
 {
 "Key": "default",
 "AllowGet": true,
 "AllowPost": true,
 "AllowPut": true,
 "AllowDelete": true
 }
 ]
}

Version History

Please refer to CHANGELOG.md for details.

Product Versions Compatible and additional computed target framework versions.
.NET net6.0 net6.0 is compatible.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 is compatible.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 was computed.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.3 1,905 8/7/2023
2.0.2 3,908 12/27/2022
2.0.1.2 2,370 8/11/2022
2.0.1.1 781 1/3/2022
2.0.1 480 1/3/2022
2.0.0.1 496 1/1/2022
1.3.0.1 1,012 11/13/2021
1.3.0 4,010 4/15/2021
1.2.7 711 11/16/2020
1.2.6 711 11/16/2020
1.2.5 11,508 8/1/2020
1.2.0 3,051 3/23/2020
1.1.0 836 10/1/2019

.NET 6 support