ejs template syntax, flow control, express api to create interfaces

ejs template syntax

  <% '脚本' 标签,用于流程控制,无输出。
  <%= 输出数据到模板(输出是转义 HTML 标签) ( 不会编译html标签)
  <%- 输出非转义的数据到模板( 会编译html标签 )

What is Process Control?

Analyzing conditions
if
the loop control
for
forEach ...
the while
do the while ...

Rendering backend

The rear end by a template (compatible html) + backend template syntax ---- "html ----> sent to the front

This type of project we call it 'does not separate the front and rear end of the project'

If you encounter this type of project:
java: find someone to build java java runtime environment on your computer

express api to create server (Interface)

  1. api server requires the use of test tools to test, the browser can not display
    summary: api front-end server is to create an interface

Note: When the data type of the interface to the front end of the rear end engineer engineers transmitted a string type json
distal engineers need to use the JSON.parse () Conversion

  1. restful api rule (rule exposed interface)

For example:
HTTP: // localhost: 3000 / Product Product Interface

要求: 删除商品中的一条 

http://localhost:3000/product/delete   删除一条商品的接口

要求: 添加一条商品

http://localhost:3000/product/add  添加一条商品接口

要求: 修改一条商品的信息

http://localhost:3000/product/change 修改一条商品接口


上面这种做法对后端压力比较大
  对一个的数据的操作,接口太多了

为了解决上面的冗余

我们使用了restful api的规则


  什么是restful api ?

    一个接口用不同数据请求方式来暴露

      将来接口只有一个,但是数据请求方式有多个

        http://localhost:3000/product 

          get 
          post
          delete
          put
          options
          head

Summary:
1. Use restful api to expose interfaces (the interface of the plurality of data requests)
cross-domain 2. cors intermediate piece
3. The front end of the sent data, how to accept the rear end
- GET req.query
- POST req.body

Back-end interface documentation (template to write)

https://www.showdoc.cc/

Guess you like

Origin blog.csdn.net/weixin_45213847/article/details/93303475