Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spike: Booter for creating REST APIs from model files #2738

Closed
3 tasks done
bajtos opened this issue Apr 12, 2019 · 4 comments
Closed
3 tasks done

Spike: Booter for creating REST APIs from model files #2738

bajtos opened this issue Apr 12, 2019 · 4 comments

Comments

@bajtos
Copy link
Member

bajtos commented Apr 12, 2019

Part of From model definition to REST API with no custom repository/controller classes #2036

In #2736, we will implement a component providing CRUD REST Controller class that can be used to expose models via REST API.

In this spike, we will find out how to implement a booter that will read model configuration from JSON files, load controllers contributed by extensions, and connect those two parts together to expose REST APIs.

Prerequisites

(1)
An extension exporting a Controller, e.g. #2736. We can build a minimal version of such extension as part of this spike if needed.

(2)
Configuration format. Let's start with the convention described in #2036. If it turns out to be difficult to implement, then propose a better one.
For example, to create a Product model, attach it to a db datasources and expose a CRUD REST API, all that the developer needs is to add the following two files to their project (plus any npm packages that implement this functionality):

src/models/product.ts:

@model()
export class Product extends Entity {
  @property()
  name: string;
}

public-models/product.json:

{
  "model": "Product",
  "pattern": "Crud",
  "dataSource": "db",
}

Note: having config for multiple models in a single JSON file, as we do in LB 3.x, can quickly become a maintenance nightmare - see strongloop/loopback#1316. It will be better to have one config file per model.

An example file for a model using KeyValue pattern (not CRUD) - public-models/cache-entry.json:

{
  "model": "CacheEntry",
  "pattern": "KeyValue",
  "dataSource": "redis"
}

IMPORTANT: Keep in mind that TypeScript compiler does not copy arbitrary JSON files from src to dist. A possible solution is to keep model configuration files in /public-models directory (outside of /src).

Acceptance criteria

  • A design proposal and PoC implementation showing how extensions can contribute controllers that can be picked by a Booter. Preferably leverage ExtensionPoint/Extension pattern as shown by our greeter example.

  • A PoC implementation of a booter parsing model configuration files, gathering controllers contributed by extensions, and using this information to build REST APIs for models as configured. Implementation-wise, start with the approach outlined in From model definition to REST API with no custom repository/controller classes #2036 (comment).

  • How to deal with Repositories? CrudRestController requires CrudRepository, CrudKeyValueController requires KeyValueRepository. We need a way (or a convention) allowing extension developers building different controller implementations to specify which repository should be used.

@b-admike
Copy link
Contributor

b-admike commented May 30, 2019

Timebox for a week and a half. @bajtos question from estimation (Janny); Does the spike's scope have generation of relational APIs for the models if they're defined? Estimation is based on not including relational APIs.

@bajtos
Copy link
Member Author

bajtos commented Jun 14, 2019

Generation of relational APIs is out of scope of #2036, see #2483. I updated the description of #2036 to make it more clear.

I think it makes sense to leave out generation of relational APIs out of scope of the spike too 👍

@bajtos
Copy link
Member Author

bajtos commented Aug 29, 2019

WIP proposal: #3617

@bajtos
Copy link
Member Author

bajtos commented Sep 13, 2019

Follow-up stories:

I am closing the spike as done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants