diff --git a/cloud/wfm-rest-api/README.md b/cloud/wfm-rest-api/README.md index 0a627a6..1f242ea 100644 --- a/cloud/wfm-rest-api/README.md +++ b/cloud/wfm-rest-api/README.md @@ -30,14 +30,27 @@ See demo application integration or [example application](./example) for more de ### Custom database integrations -Custom database integrations are possible thanks to `CrudRepository` interface. -See Api documentation for more details. +Custom database integrations are possible thanks to `PagingDataRepository` interface. ## Rest API Module provides a way to dynamically create API for different business objects. Created api will use simplified implementations for typical create, read, delete and update operations. It's not recomended to use `wfm-rest-api` outside the WFM framework. Please use database driver or ORM framework or your choice. +## Rest API structure + +API produces and expects JSON objects. +Structure of payload will vary depending on the interface passed as generic parameter to `PagingDataRepository` +For example: + +```typescript +interface MyData{ + name:string + fieldNumber:1 +} +const repository = new PagingDataRepository(); +``` + ## Rest API definitions Definitions apply to every object exposed by this API. Placeholder `{object}` can be replaced by `workflow`, `workorder` and `result`. @@ -76,28 +89,38 @@ Retrieve specific object by id Example `/workorders/B1r71fOBr` +Return 204 + ### Save object > POST {object}/ +Paylod should contain at least `id` field that will be used as object id. + ### Update object > PUT {object}/:objectId +Where `:objectId` is an `id` field of the object. + ### Delete object > DELETE {object}/:objectId +Where `:objectId` is an `id` field of the object. + ### Error handling In case of error express `next` callback is being called with `ApiError` instance. Users should build their own middleware for global error handling in their application. -Api returns non 200 status in case of error. +Api will returns non 200 status in case of error. `400` - For user input error (missing required field etc.) `500` - For internal server errors +Api will return `204` status code if content is missing (for example invalid id was provided) + For every error `ApiError` object is being returned. For example: diff --git a/cloud/wfm-rest-api/src/data-api/PagingDataRepository.ts b/cloud/wfm-rest-api/src/data-api/PagingDataRepository.ts index 3224556..6a55804 100644 --- a/cloud/wfm-rest-api/src/data-api/PagingDataRepository.ts +++ b/cloud/wfm-rest-api/src/data-api/PagingDataRepository.ts @@ -11,6 +11,7 @@ import { PageResponse } from '../data-api/PageResponse'; * Interface is being used internally to perform database operations for WFM models * It's not recomended to use it for other application business logic. * + * T - interface with fields that are expected to be returned by this repository */ export interface PagingDataRepository {