pip_services_attachments 1.0.0
pip_services_attachments: ^1.0.0

Dart native

Blob Attachments microservice for Pip.Services in Dart. It records all documents that attached to a particilar blob.

Pip.Services Logo
Attachments Microservice #

This is a blob attachments microservice from Pip.Services library. It records all documents that attached to a particilar blob. When last document is disattached, the blob gets removed.

The microservice currently supports the following deployment options:

  • Deployment platforms: Standalone Process, Seneca
  • External APIs: HTTP/REST, Seneca
  • Persistence: Flat Files, MongoDB

This microservice has no dependencies on other microservices.

Quick Links:

Contract #

Logical contract of the microservice is presented below. For physical implementation (HTTP/REST), please, refer to documentation of the specific protocol.

class ReferenceV1 {
  String id;
  String type;
  String name;

class BlobAttachmentV1 implements IStringIdentifiable {
  String id;
  List<ReferenceV1> references;

abstract class IAttachmentsV1 {
  Future<BlobAttachmentV1> getAttachmentById(
      String correlationId, String attachmentId);
  Future<List<BlobAttachmentV1>> addAttachments(
      String correlationId, ReferenceV1 reference, List<String> ids);

  Future<List<BlobAttachmentV1>> updateAttachments(String correlationId,
      ReferenceV1 reference, List<String> oldIds, List<String> newIds);

  Future<List<BlobAttachmentV1>> removeAttachments(
      String correlationId, ReferenceV1 reference, List<String> ids);

  Future<BlobAttachmentV1> deleteAttachmentById(
      String correlationId, String attachmentId);

Download #

Right now the only way to get the microservice is to check it out directly from github repository

git clone git@github.com:pip-services-content/pip-services-attachments-dart.git

Pip.Service team is working to implement packaging and make stable releases available for your as zip downloadable archieves.

Run #

Add config.yaml file to the root of the microservice folder and set configuration parameters.

Example of microservice configuration

# Container descriptor
- descriptor: "pip-services:context-info:default:default:1.0"
  name: "pip-services-attachments"
  description: "Attachments microservice for pip-services"

# Console logger
- descriptor: "pip-services:logger:console:default:1.0"
  level: "trace"

# Performance counters that posts values to log
- descriptor: "pip-services:counters:log:default:1.0"
  level: "trace"

# In-memory persistence. Use only for testing!
- descriptor: "pip-services-attachments:persistence:memory:default:1.0"

# File persistence. Use it for testing of for simple standalone deployments
- descriptor: "pip-services-attachments:persistence:file:default:1.0"
  path: {{FILE_PATH}}{{^FILE_PATH}}"./data/attachments.json"{{/FILE_PATH}}

# MongoDB Persistence
- descriptor: "pip-services-attachments:persistence:mongodb:default:1.0"
    uri: {{{MONGO_SERVICE_URI}}}
    database: {{MONGO_DB}}{{#^MONGO_DB}}app{{/^MONGO_DB}}
    username: {{MONGO_USER}}
    attachment: {{MONGO_PASS}}

# Default in-memory persistence
- descriptor: "pip-services-attachments:persistence:memory:default:1.0"

# Default controller
- descriptor: "pip-services-attachments:controller:default:default:1.0"

# Common HTTP endpoint
- descriptor: "pip-services:endpoint:http:default:1.0"
    protocol: "http"
    host: ""
    port: 8080

# HTTP endpoint version 1.0
- descriptor: "pip-services-attachments:service:http:default:1.0"

# Heartbeat service
- descriptor: "pip-services:heartbeat-service:http:default:1.0"

# Status service
- descriptor: "pip-services:status-service:http:default:1.0"

For more information on the microservice configuration see Configuration Guide.

Start the microservice using the command:

dart ./bin/run.dart

Use #

The easiest way to work with the microservice is to use client SDK. The complete list of available client SDKs for different languages is listed in the Quick Links

If you use dart, then get references to the required libraries:

Add pip-services3-commons-dart, pip-services3-rpc-dart and pip-services_attachments packages

import 'package:pip_services3_commons/pip_services3_commons.dart';
import 'package:pip_services3_rpc/pip_services3_rpc.dart';

import 'package:pip_services_attachments/pip_services_attachments.dart';

Define client configuration parameters that match the configuration of the microservice's external API

// Client configuration
var httpConfig = ConfigParams.fromTuples(
	"connection.protocol", "http",
	"connection.host", "localhost",
	"connection.port", 8080

Instantiate the client and open connection to the microservice

// Create the client instance
var client = AttachmentsHttpClientV1(config);

// Configure the client

// Connect to the microservice
  await client.open(null)
}catch() {
  // Error handling...
// Work with the microservice
// ...

Now the client is ready to perform operations

    // Create the attachment
    try {
      var attachments = await client.addAttachments('123', ReferenceV1(
              id: '000000000000000000000011', type: 'goal', name: 'Goal 1'),
              ['1', '2']);
      // Do something with the returned attachments...
    } catch(err) {
      // Error handling...     
// Authenticated
try {
var attachment =
          await controller.getAttachmentById('123', '1');
    // Do something with attachment...

    } catch(err) { // Error handling}

Acknowledgements #

This microservice was created and currently maintained by

  • Sergey Seroukhov
  • Nuzhnykh Egor.