Test

<back to all web services

GetItems

import 'package:servicestack/servicestack.dart';

class Item implements IConvertible
{
    String name = "";
    String description = "";

    Item({this.name="",this.description=""});
    Item.fromJson(Map<String, dynamic> json) { fromMap(json); }

    fromMap(Map<String, dynamic> json) {
        name = json['name'] ?? "";
        description = json['description'] ?? "";
        return this;
    }

    Map<String, dynamic> toJson() => {
        'name': name,
        'description': description
    };

    getTypeName() => "Item";
    TypeContext? context = _ctx;
}

class Items implements IConvertible
{
    List<Item> results = [];

    Items({this.results=const []});
    Items.fromJson(Map<String, dynamic> json) { fromMap(json); }

    fromMap(Map<String, dynamic> json) {
        results = JsonConverters.fromJson(json['results'],'List<Item>',context!) ?? [];
        return this;
    }

    Map<String, dynamic> toJson() => {
        'results': JsonConverters.toJson(results,'List<Item>',context!)
    };

    getTypeName() => "Items";
    TypeContext? context = _ctx;
}

class GetItems implements IConvertible
{
    GetItems();
    GetItems.fromJson(Map<String, dynamic> json) : super();
    fromMap(Map<String, dynamic> json) {
        return this;
    }

    Map<String, dynamic> toJson() => {};
    getTypeName() => "GetItems";
    TypeContext? context = _ctx;
}

TypeContext _ctx = TypeContext(library: 'test.servicestack.net', types: <String, TypeInfo> {
    'Item': TypeInfo(TypeOf.Class, create:() => Item()),
    'Items': TypeInfo(TypeOf.Class, create:() => Items()),
    'List<Item>': TypeInfo(TypeOf.Class, create:() => <Item>[]),
    'GetItems': TypeInfo(TypeOf.Class, create:() => GetItems()),
});

Dart GetItems DTOs

To override the Content-type in your clients, use the HTTP Accept Header, append the .jsv suffix or ?format=jsv

HTTP + JSV

The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.

POST /jsv/reply/GetItems HTTP/1.1 
Host: test.servicestack.net 
Accept: text/jsv
Content-Type: text/jsv
Content-Length: length

{
	
}
HTTP/1.1 200 OK
Content-Type: text/jsv
Content-Length: length

{
	results: 
	[
		{
			name: String,
			description: String
		}
	]
}