Is it difficult to create a restful style API interface? Obviously 5 minutes will do!
1. Thinking
01. Is it difficult to create an API interface?
software testing engineer:
◆ Only tested the API interface, never created it
◆ You should master a back-end development language and back-end development framework! ?
◆ The brain capacity is limited, it's scary to think about it
02. How to create an API interface?
◆ Use Django restframework to quickly create a restful style API interface
◆ The serializer and view set provided by the Django restframework framework can be easily implemented
◆ Simple and efficient, low learning cost
2. Build the project
01, create a project
◆ Open pycharm
◆ Create project
◆ Use Douban source to install Django Django restframework markdown
◆ Create a Django project
◆ Run python manage.py runserver in Terminal, visit in the browser, if the following page appears, it means success
Three, create an API interface
01, create a sub-application and migrate
02, add configuration
Add the following configuration in CreateRestfulAPI/settings.py:
03, write code
◆ Create users/serializers.py file
◆ Add the following code in users/views.py
◆ Create sub-route users/urls.py file
◆ Add the following code in the global routing file CreateRestfulAPI/urls.py
◆ Create super administrator user
◆ Run the project
Enter at the command line: python manage.py runserver
04. Effect display
◆ Visit the homepage
◆ Log in as a super administrator user
◆ Manage users (POST, GET)
◆ Manage users (GET, PUT, DELETE)
Four, summary
◆ This article introduces a method to create an API interface conforming to the Restful style
◆ Including the construction of Django project environment
◆ Realize the creation method of GET, POST, PUT, DELETE interface, simple and efficient
◆ This article is excellent and original, there are deficiencies, please advise!
Recommend a software testing learning exchange group: 785128166, there are shared videos, interview guidance, test materials, mind maps, and videos in the group. They are all dry goods, you can download and watch. Mainly share test foundation, interface test, performance test, automated test, TestOps architecture, Jmeter, LoadRunner, Fiddler, MySql, Linux, resume optimization, interview skills, and actual video data of large-scale test projects. Use every minute and every second of your time to learn to improve yourself, and don't use "no time" to conceal your mental laziness! Try hard while you are young, and give your future self an explanation!
Public number: Programmer Erhei, after paying attention, you can receive a large amount of learning materials for free.
Good things should be shared with friends