createNew method

Future<ResourceCreated> createNew(
  1. String type, {
  2. Map<String, Object?> attributes = const {},
  3. Map<String, Identifier> one = const {},
  4. Map<String, Iterable<Identifier>> many = const {},
  5. Map<String, Object?> meta = const {},
  6. Map<String, Object?> documentMeta = const {},
  7. Map<String, String> headers = const {},
  8. Iterable<String> include = const [],
})

Creates a new resource in the collection of type type. The server is responsible for assigning the resource id.

Optional arguments:

  • attributes - resource attributes
  • one - resource to-one relationships
  • many - resource to-many relationships
  • meta - resource meta data
  • documentMeta - document meta
  • headers - any extra HTTP headers

Implementation

Future<ResourceCreated> createNew(
  String type, {
  Map<String, Object?> attributes = const {},
  Map<String, Identifier> one = const {},
  Map<String, Iterable<Identifier>> many = const {},
  Map<String, Object?> meta = const {},
  Map<String, Object?> documentMeta = const {},
  Map<String, String> headers = const {},
  Iterable<String> include = const [],
}) async {
  final response = await send(
      baseUri.collection(type),
      Request.post(OutboundDataDocument.newResource(NewResource(type)
        ..attributes.addAll(attributes)
        ..relationships.addAll({
          ...one.map((key, value) => MapEntry(key, ToOne(value))),
          ...many.map((key, value) => MapEntry(key, ToMany(value))),
        })
        ..meta.addAll(meta))
        ..meta.addAll(documentMeta))
        ..headers.addAll(headers)
        ..include(include));

  return ResourceCreated(
      response.http, response.document ?? (throw FormatException()));
}