Home  >  Article  >  Backend Development  >  An introduction to how to build a restful resource server in a short time

An introduction to how to build a restful resource server in a short time

不言
不言Original
2018-07-10 14:17:071709browse

This article mainly introduces the method of how to build a restful resource server in a short time. It has certain reference value. Now I share it with you. Friends in need can refer to it.

Use Mins You can build a simple restful resource server in five seconds (excluding file download time...).

Preparation

First download Mins:

wget https://github.com/chenhg5/mins/releases/download/0.0.2/mins_mac -O mins

Since I am under a mac system, I download the binary file corresponding to mac. The corresponding version can be downloaded for the corresponding system. The download link is: https://github.com/chenhg5/mi...

An introduction to how to build a restful resource server in a short time

After downloading, you can choose to put the binary file into the environment path. You need to give mins execution permission:

chmod +x mins

Then you need to write a configuration file config.ini, the content is as follows:

[server]
port = 4006

[database]
addr = localhost
port = 3306
user = root
password = root
database = example

example is the corresponding mysql resource database, which has a users table.

Start

Then start Mins and you’re done.

./mins -c ./config.ini

An introduction to how to build a restful resource server in a short time

Experience

Then we add a new data into the users table of example:

curl -X POST \
  http://localhost:4006/resource/users \
  -F name=jack \
  -F sex=0

You can see that the database has been added A piece of data:

An introduction to how to build a restful resource server in a short time

Then you can find out this data:

curl -X GET http://localhost:4006/resource/users/id/1
{"code":200, "msg":"ok", "data": {"id":1,"name":"jack","sex":0}}

Modify data

curl -X PUT http://localhost:4006/resource/users/id/1 -F name=Mick

Delete data

curl -X DELETE http://localhost:4006/resource/users/id/1

static file

In addition to adding, deleting, modifying, and checking resources, mins also built a static file server. Through mins, you can access static files under the current path, such as html, css, image files, etc.

Performance

It is developed using golang's fasthttp network library, and the performance is naturally great.

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

Introduction to Swoole memory operation (Table)

How to modify the WordPress image address to a relative path

The above is the detailed content of An introduction to how to build a restful resource server in a short time. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn