Skip to content

gRPC Development Patterns

Sandro Meireles edited this page Feb 23, 2021 · 9 revisions

Using some development standards can help us to implement a dockable, safe and easy to maintain solution.

Creating a new gRPC App:

To speed up the work, we can create an app using Django itself. In /rapidpro-apps/weni/

Type it:

> django-admin startapp <app_name>

A new directory should appear containing the name of the application.

Basic structure

By default Django generates several files, which for us will not be useful, therefore, we must delete them (or rename them). The final structure we want should look like this:

<app_name>
├── apps.py
├── __init__.py
├── serializers.py
├── services.py
├── tests.py
└── urls.py

Within your app create a new directory named: grpc_gen, it must contain a __init__.py.

<app_name>
├── grpc_gen
│   └── __init__.py
├── apps.py
├── __init__.py
├── ...
└── urls.py

We must run the protocol buffer compiler pointing to <app_name>/grpc_gen/

Adjusting the App

In order for Django to be able to identify your application and run all your implementations smoothly, we need to make some basic changes.
Modify the apps.py file, in name = '<app_name>' we must add the weni prefix before the app name.

class ExampleConfig(AppConfig):
-   name = '<app_name>'
+   name = 'weni.<app_name>'
Clone this wiki locally