Wechat small program development platform has just opened a new function: cloud development. To put it simply is to reduce the cost of building the back end of wechat small program for developers again. This article just happens to be in the public test of this product to quickly get started and see what features are convenient for developers to update.
Micro channel small program has been keeping a relatively stable pace of function opening and updating, not radical but not neglection, it has been like the pace of micro channel products, and in life, we use micro channel small program frequency is also slowly rising, such as KFC self-service ordering a meal, ordering some unpopular goods and so on. And the outline of “wechat small program development video Tutorial” that I updated for free has also been revised and increased from 40 to 60 sets. After the release of cloud development, the course is estimated to be updated to about 80 sets. Each major platform has a total of nearly 20W of play, students in need can watch free learning, guidance.
1. Public test application and development tool update
First of all, I need to apply for the public beta permission of “Cloud development” on the page of the cloud development document. Mine was notified by email in half a day.
You will then need to download the beta version of the development tool, which contains the functional modules for cloud development.
2. Initialize the project
According to the official word, you can learn to view it by creating an official DEMO project directly by selecting “Create Cloud Development Quick Start Template” when creating a new project.
The new project structure is shown on the left in the figure. Compared with the previous project structure, there are more local mappings for cloud file storage.
3. Functions of cloud development
The official instructions are as follows:
At present, three basic capabilities are provided: cloud function: code running in the cloud, wechat private protocol natural authentication, developers only need to write their own business logic code database: A JSON database file storage that can be operated in the front end of the small program and read and write in the cloud function: Upload/download cloud files directly in front of the small program, and manage them visually in the cloud development console
3.1 cloud function
A cloud function is a piece of code that runs in the cloud and can be written in a development tool, uploaded and deployed with one click, without the need to manage a server. An API specifically for cloud function calls is provided within the applets. Developers can obtain the context of each call (appID, OpenID, etc.) in the cloud function, and obtain the naturally trusted user login state (OpenID) without maintaining complex authentication mechanism. Open the use of Node.js and other frameworks to write “back-end” business logic, can be directly deployed in the cloud platform, completely do not need to consider the domain name, server, packaging and publishing, operation and maintenance and other trivial matters, we experience this function for the development of some small projects to bring convenience and benefits.
3.2 database
Cloud development provides a JSON database where, as the name implies, each record is a JSON-formatted object. A database can have multiple collections (equivalent to tables in relational data), which can be viewed as a JSON array where each object in the array is a record in the form of a JSON object. In this case, the storage of the database does not need to be considered, directly provides a database similar to NOSQL, and free storage space up to 1 gb, enough to use.
3.3 File Storage
Cloud development provides a space for file storage, and provides the cloud download capability of uploading files to the cloud with permission management. Developers can use the cloud file storage function through APIS on the small program side and the cloud function side. You can call wx.cloud.uploadFile and wx.cloud.downloadFile on the applet side to upload and download cloud files. This is a CDN that directly provides you with a static file, or Tencent directly provides it. The free capacity directly reaches 5G. I think small projects are generally inexhausted in the early stage.
4. Cloud development console
As shown in the figure below, you can directly call up the independent cloud development console in the development tool toolbar, and graphical management is also very convenient.
5. Functional hands-on test
Let’s take a look at the implementation process of the cloud function with the official DEMO.
The above is the logic defined by the cloud. The “back end” is quoted because the API of some small programs can be directly called here, without having to deal with some additional logic. For example, the method of obtaining OpenID of the back end is completely different under different language frameworks.
Once the cloud function is defined, it can be uploaded and published by right-clicking, and then it can be called directly from the foreground.
It’s seamless and silky.
6. Conclusion
According to the official DEMO template project has a lot of DEMO learning code, we are interested in directly to initialize the project after learning, here will not post more code description. As for the promotion of the small program development environment after the release of this function, you can think about it yourself. I think it is as the driving force for many incubation project developers the most official big recruit, dispense with the domain name for the record, database operations, server operations, the back-end development, packaging and so on work, under a small program development account can also set up two such background, the clouds no matter from the aspects such as efficiency, space, capacity, There is probably no better third-party solution than what the authorities can optimize. Our DevOpenClub community has also begun to incubate some micro program projects, interested friends can find like-minded friends there, use their spare time to realize some of their own ideas, the cost of development has been very very low.