There is no need to change the URL for automated version management at the backend !, Backend url

Source: Internet
Author: User

There is no need to change the URL for automated version management at the backend !, Backend url

Every time you upgrade the interface version, the backend, front-end, and client are all painful:

Backend: to be compatible with the old client version, the previous interfaces cannot be moved. You have to write new interfaces and documents!

Front-end: Okay, that is, the version number is everywhere, which is annoying.

Android: Hurry up. Why don't the server stop for too long. By the way, do you know how long it will take to compile? Tears rush...

Front-end: Right. Don't stop for too long. Do not write any more wrong documents. The last time you copied and pasted v3, I called the interface for a long time. It turned out to be v4...

IOS: I am also stuck...

Backend: Well, I will pay attention to writing documents as soon as possible.

Back-end: In addition, the old domain name http://api.aaa.com/v4 will remain open, so that the 3.0 client request will not be hung as last time.

Backend: @ frontend is correct. You can use a global BASE_URL to save it. You can change it to another place.

Android: That's what we do!

IOS: So are we. I encapsulated them.

IOS: but the problem is that there are often multiple interface versions, or you need to write several base_urls, from BASE_URL_V2 to BASE_URL_V4.

Android: Alas, this is no way.

Front-end: We did the same thing now, but the old guy was not encapsulated, and everything was written...

 

 

Backend: Zhou Ge, it's annoying to upgrade the interface version. Do you have any good solutions?

Zhou Ge: Let's talk about your problem.

Backend: New interfaces and documents must be written each time, and the server must be restarted. The front-end and client always complain about Domain Name Change and document errors.

The project is very busy, the document is copied and pasted, and there will always be some places left unchanged.

But do not copy and paste it. It is too much trouble to re-write this format!

Zhou Ge: Haha, we used to encounter this problem. Now we have solved it. Try this

Week: https://github.com/TommyLemon/APIJSON

Backend: Wow, there is such a powerful backend framework! I only used SSH.

Zhou Ge: I only learned this last month. My friend recommended it. I tried it for a week and it was very easy to use. I didn't have any major problems. I just got into the project.

Zhou Ge: SSH is too heavy. In the old project, APIJSON is mainly used to implement new interfaces. In the new project, only APIJSON is used.

Backend: Yes. But how does it solve the version issue? Not mentioned in the document.

Zhou Ge: I wrote it at the bottom. Http: // 39.108.143.172/

Backend: You can specify the version to be used by passing the version in the outermost layer. if the version is not passed or the version is <= 0, the latest version is used. ??

Zhou Ge: The description is really simple. I asked the author, he said:

 

 

TommyLemon:

You can pass in a version to specify the version number of the API used during the request, for example, querying user privacy information:

URL: http: // 39.108.143.172: 8080/gets

Form:

{    "Privacy": {        "id": 82001,        "_password": "123456"    },    "tag": "Privacy",    "version": 1}

In addition, you only need to pass a global default version when logging on. This is used by default for all interfaces that need to be logged on (typically the majority.

{    "type": 0,    "phone": "13000082001",    "password": "123456",    "version": 1}

 

Therefore, you can omit the version when querying user privacy information:

{    "Privacy": {        "id": 82001,        "_password": "123456"    },    "tag": "Privacy"}

 

Because the version passed above is the same as the global default version, the results returned by the server are the same:

{    "Privacy": {        "id": 82001,        "certified": 1,        "phone": 13000082001,        "balance": 8067    },    "code": 200,    "msg": "success"}

 

Of course, if a request requires an interface different from the global default version, you can also specify the current version:

{    "Privacy": {        "id": 82001,        "_password": "123456"    },    "tag": "Privacy",    "version": 2}

 

Because the verification configuration has been changed for interfaces of version 2nd, the returned results are different:

{"Privacy": {"id": 82001, "_ password": "123456"}, "code": 406, "msg ": "Privacy does not allow _ password and other fields in [_ password, _ payPassword! "}

 

Note: This interface requires logon permissions. Please click Login in the upper right corner before requesting.

Online APIJSON Testing

 

Zhou Ge: I tried it one by one on the test webpage. It is true.

Backend: But there is another problem: multiple versions can coexist in the project. Does it need to maintain multiple versions at the same time?

Zhou Ge: Haha. There were only two methods in the past:

1. The frontend calls the corresponding api version based on the requirements, and only new APIs are added to the backend.

2. the frontend only uses one version. the backend also provides an api v3 corresponding to the new version of api v2 that does not need to be changed. This process is the same as that of api V2. The Code of v2 can be extracted as a public function.

Or you can simply redirect to v2. This operation is simpler, but it will lose some performance.

Zhou Ge: to use APIJSON, you only need to change the version of the old api version to a uniform latest version. if the version in the request does not exist, it is automatically transferred to the closest version higher than it.

Backend: that is, I changed v1 and v2 to v3, and then passed v1 or v2 to the front end. Then it is switched to v3? If it is not changed, go to v2?

Zhou Ge: Yes. If version or version is not set to <= 0, the latest version is required. This is useful when fixing some api vulnerabilities. You can remove or change the version in the front-end request to 0.

Backend: I think it is easier to change the version of the api to the latest version.

Zhou Ge: indeed, you are very smart, young man.

Backend: Haha. Thank you, Zhou GE. Let me try it.

Backend: the author is awesome.

 

Zhou Ge: Haha, I was curious about who could write such a framework.

Zhou Ge: I don't need to write any interfaces. They are all automatically implemented by the Framework. Now, no one is pushing the interface again. Haha!

Backend: It is really easy to use. In the future, it will be done if the front-end client passes a version upon logon.

Backend: however, there are some interfaces in the project that can be accessed without logon, such as registration and password retrieval. Each time, only one version can be uploaded.

Zhou Ge: Yes, but most interfaces are accessible only after logon.

Backend: Yes.

Backend: By the way, the normal query request does not seem to have a version example.

Zhou Ge: because no Haha is required, the author said that GET and HEAD requests are all open requests and there is no version limit. I tried it.

Backend: that is, do not use version?

Zhou Ge: Yes, and the request is very flexible. You can customize the request content and JSON structure. You do not need to write a lot of query request interfaces.

Backend: That's great. Let's go to Star.

 

 

Backend: @ frontend @ Android @ new iOS interface is ready.

Back-end: we change the new request of the main domain name into a http://api.aaa.com, later login and then pass a version.

{  "version":5}

Front-end: so fast?

IOS: so fast?

Android: so fast?

Backend: a new framework is used!

Android: Do you need to change the version number v5?

IOS: will it be added later?

Backend: No, no v6 or v7 in the future. The domain name will not be changed.

IOS: What interfaces Do you not need to log on?

Backend: No worries. These interfaces are very stable and will not be moved for the time being.

Android: Yes

IOS: Like

Front-end: Amazing. How can this be done?

Backend: Let's take a look at this. The interfaces after the backend are written in the new framework.

Back: https://github.com/TommyLemon/APIJSON

IOS: supported

Front end: + 1

Android: Great. I also have fun with the backend!

 

 

 

APIJSON-backend super-light speed development framework

 

GithubSource code and documentation (click in the upper-right cornerStar supports ^_^)

Https://github.com/TommyLemon/APIJSON

Download the client (test server address:Http: // 39.108.143.172: 8080)

APIJSONClientApp.apk

 

 

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.