5 Seconds to build a RESTful resource server

Source: Internet
Author: User

Using mins can be within five seconds (excluding download file time ...) Build a simple RESTful resource server.

Get ready

First download mins:

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

Because I am under Mac system, so download binary files corresponding to Mac. Corresponding system can download the corresponding version, download link: https://github.com/chenhg5/mi ...

Download OK, you can choose to put the binary file into the environment path. Need to execute permissions for mins:

chmod +x mins

Next, you need to write a configuration file Config.ini, which reads as follows:

[server]port = 4006[database]addr = localhostport = 3306user = rootpassword = rootdatabase = example

Example is the corresponding MySQL resource database, which has a users table.

Start

Then start the mins and it's done.

./mins -c ./config.ini

Experience

Then we add a data to the users table in example:

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

You can see that the database adds a new piece of data:

This data can then be found:

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

modifying 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 files

In addition to the resource additions and deletions, mins also built a static file server, through mins can access the current path of static files, such as html,css,image files.

Performance

With the development of Golang's Fasthttp network library, the performance is naturally great.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.