Build your API
- Once you are in the project editor, You can create a new root namespace (API) by clicking the "New API" button within the project or by using the keyboard shortcuts just press
A
.
Keyboard shortcuts mapping and description is always available by pressing Shift + ?
Start by creating the base API, which will hold all of our service data models at the moment. Give it a descriptive name such as: "bookstore"
Create a new package under the "bookstore" API, a package is container for different resources (
Service
,Message
andEnum
) that resembles data structure in your schema.First we will create a package that will hold the main entities of our data model, we will call it "book" which will hold our "Book" message.
Name the package and give it a short description (optional).
Notice that the package path is including a "Version Component" (v1
) as we might want to add a breaking changes to serve further developmnets to the schema in the future.
After the package "book" has been created you will be navigated to the "Package Page" which hold all the associated package resources and metadata.
- To create a new message under "book" package, click the "New Message" button within the package page or by using keyboard shortcuts
M
.
Give the message a name: "Book" this will hold all the book metadata.
Edit the "Book" message:
A. Click on the new message name under "Messages" card inside the "Package Page"
B. Define the "Book" fields - Click on "New Field":
C. Define field name: "Name" The unique book name.
D. Chose field type: "String".
E. Configure if field is of "Array" type or not in our case it is NOT.
Then save the field info by clicking on the checkmark.
Create another message for our "BookStore" model - you can create messages and other resources with right-click the desired parent in the tree panel Give it a name: "GetBookRequest"
Now inside the newly created message create the following field:
Name - The book title name the user will query for.
A. Chose field type to be of "String"
B. Configure if the field is of "Array" type or not: in our case NOT
Then save the field info by clicking on the checkmark.
Now we have our first messages ready to be consumed via a service, use the "Sylk Spotlight" for easy navigation and quick actions within the platform.
Click on
Ctrl + E
on Windows and⌘ + E
on Mac - A dialog will open with auto-complete input box. type: New Service and clickEnter
Give the service a name: "BookStoreService" and click save.
Once the service is created you will be navigated to the "Service Page", there you can manage the service resources such as
Method
s.To create a new method, click the "New Method" button within the service.
Give the method a name, select the message it uses, and define its input and output parameters.
A. Define method name: "ListBooks"
B. Chose method input type: "Empty"
✏️ NoteYou can use a well-known types created by google, all known types are listed here
C. Chose method output type: "Book"
D. Chose method type: "Server Stream"
Then save the method info by clicking on the checkmark.
Now we should complete our "BookStoreService" functionality with the next method:
A. Define method name: "GetBook"
B. Chose method input type: "GetBookRequest"
C. Chose method output type: "Book"
D. Chose method type: "Unary"
Then save the method info by clicking on the checkmark.
Now your Sylk's cloud Beta project is ready and you can start implemanting what your service does best.
That's it! With these simple steps, you can create a new project, package, message, service, and method using the Sylk Cloud Platform.