createNew method
Future<ResourceCreated>
createNew(
- String type, {
- String? lid,
- Map<
String, Object?> attributes = const {}, - Map<
String, NewIdentifier> one = const {}, - Map<
String, Iterable< many = const {},NewIdentifier> > - Map<
String, Object?> meta = const {}, - Map<
String, Object?> documentMeta = const {}, - Map<
String, List< headers = const {},String> > - Iterable<
QueryEncodable> query = const [],
Creates a new resource in the collection of type type
.
The server is responsible for assigning the resource id.
Optional arguments:
lid
- local resource idattributes
- resource attributesone
- resource to-one relationshipsmany
- resource to-many relationshipsmeta
- resource meta datadocumentMeta
- document metaheaders
- any extra HTTP headersquery
- a collection of parameters to be included in the URI query
Implementation
Future<ResourceCreated> createNew(
String type, {
String? lid,
Map<String, Object?> attributes = const {},
Map<String, NewIdentifier> one = const {},
Map<String, Iterable<NewIdentifier>> many = const {},
Map<String, Object?> meta = const {},
Map<String, Object?> documentMeta = const {},
Map<String, List<String>> headers = const {},
Iterable<QueryEncodable> query = const [],
}) async =>
ResourceCreated(await send(
_baseUri.collection(type),
Request.post(
OutboundDataDocument.newResource(NewResource(type, lid: lid)
..attributes.addAll(attributes)
..relationships.addAll({
...one.map((key, value) => MapEntry(key, NewToOne(value))),
...many.map((key, value) => MapEntry(key, NewToMany(value))),
})
..meta.addAll(meta))
..meta.addAll(documentMeta))
..headers.addAll(headers)
..query.mergeAll(query)));