Test

<back to all web services

GetItems

import 'package:servicestack/servicestack.dart';
import 'dart:typed_data';

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});
    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 .json suffix or ?format=json

To embed the response in a jsonp callback, append ?callback=myCallback

HTTP + JSON

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

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

{}
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: length

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