In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
How to use Serverless to quickly build a survey questionnaire in APP, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail, people with this need can come to learn, I hope you can gain something.
Preface
Serverless computing enables developers to build modern applications with greater flexibility and lower cost. Developers do not need to configure and manage infrastructure such as servers, and can devote all their energies to the core business.
Serverless is essentially different from traditional serverful development methods:
Decoupling of computing and storage; they are expanded and priced independently
Code execution no longer requires manual allocation of resources
Charge by usage.
Rapid Construction of Serverless and APP questionnaire Survey
As the core computing component of Serverless architecture, functional services can be applied to all kinds of Serverless architectures, including two categories: Web, mobile, IoT, AI and other serverless back-end and data processing system back-end.
Among them, the typical scenarios of Web and mobile serverless backend are the most widely used. This document describes how to use functional services + API gateway to build user questionnaires in Jingdong Cloud APP minute by minute.
The construction of APP questionnaire can be accomplished by two simple functions: obtaining the content of the questionnaire and submitting the answer.
Step1: creating Stora
Create a database or object storage bucket for storing questionnaire questions and users' answers. In this example, create a cloud cache Redis instance (master / slave 4GB).
Step2: create function
Create and test two functions in the function service (runtime: Python2.7)
Create function 1
Create the function jcloud-app-survey-topic: request the user PIN, the questionnaire version version, obtain the questionnaire content from the database, and package the entry file index.py and the dependent library redis SDK to the function service. The index.py code is as follows:
# coding=utf-8import jsonimport redis''' download questionnaire''def handler (event,context): if not bool (event): result = {' statusCode': 200, 'headers': {},' body': ",} return result body = event ['detail'] [' body'] body = json.loads (body) pin = body.get ('pin') "") version = body.get ('version', ") print (pin) print (version) r = redis.Redis (host='redis-v214pzrgiicq-proxy-nlb.jvessel-open-hb.jdcloud.com', port=6379, db=0) topic = r.hget (' topic_' + version, version) data = {'pin': pin,' version': version, 'topic': topic} data = json.dumps (data) result = {' statusCode': 200 'headers': {}, 'body': data,} return result
Function test
Create function 2
Create function 2jcloud-app-survey-submit: request user PIN, questionnaire version version, user answer submit, upload to database, package entry file index.py and dependent library redis SDK to function service. The index.py code is as follows.
# def handler (event,context): if not bool (event): result = {'statusCode': 200,' headers': {}, 'body': ",} return result body = event [' detail'] ['body'] body = json.loads (body) pin = body.get (' pin') "") version = body.get ('version', ") submit = body.get (' submit',") print (pin) print (version) print (submit) r = redis.Redis (host='*.jdcloud.com', port=6379, db=0) old = r.hget ('submit_' + version, pin) if old! = None: data = {' code': 1 'desc':' user have submitted'} data = json.dumps (data) result = {'statusCode': 200,' headers': {}, 'body': data,} return result r.hset (' submit_' + version, pin, submit) data = {'code': 0,' desc': 'success'} data = json.dumps (data) result = {' statusCode': 'headers': {}, 'body': data,} return result
Function test
Step 3: create a publish API
Create two API in the API gateway, bind to the corresponding function as triggers, respond to the API request through function, and publish the API to the test environment. The jcloud-app-survey-topic function binds the API trigger as follows:
The jcloud-app-survey-submit function binds the API trigger as follows:
Step 4: verify launch
Verify the correctness of the API interface through the local API interface test tool, which can be debugged with the front-end H5 page development. After the test is completed, it can be iteratively released through the function version and alias function management online function.
Above, quickly complete the launch of the APP backend, just wait for the event to be launched
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.