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 .xml suffix or ?format=xml

HTTP + XML

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

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

<GetItems xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Test.ServiceModel" />
HTTP/1.1 200 OK
Content-Type: application/xml
Content-Length: length

<Items xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Test.ServiceModel">
  <Results>
    <Item>
      <Description>String</Description>
      <Name>String</Name>
    </Item>
  </Results>
</Items>