create method

Future<ResourceUpdated> create(
  1. String type,
  2. String id, {
  3. Map<String, Object?> attributes = const {},
  4. Map<String, Identifier> one = const {},
  5. Map<String, Iterable<Identifier>> many = const {},
  6. Map<String, Object?> meta = const {},
  7. Map<String, Object?> documentMeta = const {},
  8. Map<String, List<String>> headers = const {},
  9. Iterable<QueryEncodable> query = const [],
})

Creates a new resource with the given type and id on the server.

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
  • query - a collection of parameters to be included in the URI query

Implementation

Future<ResourceUpdated> create(
  String type,
  String id, {
  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, List<String>> headers = const {},
  Iterable<QueryEncodable> query = const [],
}) async =>
    ResourceUpdated(await send(
        _baseUri.collection(type),
        Request.post(OutboundDataDocument.resource(Resource(type, id)
          ..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)
          ..query.mergeAll(query)));