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

不言
Release: 2023-04-02 22:10:01
Original
1686 people have browsed it

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
Copy after login

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
Copy after login

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
Copy after login

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

Start

Then start Mins and you’re done.

./mins -c ./config.ini
Copy after login

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
Copy after login

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}}
Copy after login

Modify data

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

Delete data

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!