With a monolith any changes require a full build and deployment of the entire application. With microservices, however, you only need to redeploy the service(s) you modified.
The Bad:
The downside is that you have to worry about changes to one service breaking its consumers. The traditional integration approach is to try to deal with this problem using versioning, but the preference in the microservice world is to only use versioning as a last resort. We can avoid a lot of versioning by designing services to be as tolerant as possible to changes in their suppliers.
The Specification:
Organize around business capabilities
Any organization that designs a system (defined broadly) will produce a design whose structure is a copy of the organization’s communication structure.
— Melvyn Conway, 1967
对比:
Monolithic的团队注重组织分工,各司其职:
Microservice的团队更加注重business capability:

The Example:
The Microservice is the Evolutionary Design, or not?
The Guardian website is a good example of an application that was designed and built as a monolith, but has been evolving in a microservice direction. The monolith still is the core of the website, but they prefer to add new features by building microservices that use the monolith’s API.
# Convert the bytes to a str. Because "The JSON object must be str, not 'bytes'"
str_response = response.decode('utf-8')
# Convert the string response to a Python dictionary object.
json_response = json.loads(str_response)
for result in json_response['d']['results']:
results.append({
'title': result['Title'],
'link': result['Url'],
'summary': result['Description']
})
如果在PHP中,也是通过类似的方法:
foreach($jsonObj->d->results as $value)
3.3 通过命令行的形式验证
在实施网页版本之前,首先通过命令行的形式保证这个API可以Working。
具体请见代码
4. 展示result
需要在Template中添加相应的search.html
需要在views中添加search(request)的view。
需要在urls.py中添加url
最后在base上添加链接。
5. 代码
import json
import urllib.request
import urllib.parse
from rango.keys import BING_API_KEY
def run_query(search_terms):
# Specify the base
root_url = 'https://api.datamarket.azure.com/Bing/Search/v1/'
source = 'Web'
# Specify how many results we wish to return per page
results_per_page = 10
offset = 0
# Warp quotes around our query terms as required by the Bing API
query = "'{0}'".format(search_terms)
query = urllib.request.quote(query)
# Constructs the latter part of our request's URL
search_url = "{0}{1}?$format=json&$top={2}&$skip={3}&Query={4}".format(
root_url,
source,
results_per_page,
offset,
query
)
# Setup authentication with the Bing servers.
# The username MUST be a blank string, and put in your API key!
username = ''
# Create a 'password manager' which handles authentication for us.
password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
password_mgr.add_password(None, search_url, username, BING_API_KEY)
# Create our results list which we'll populate
results = []
try:
# Prepare for connecting to Bing's servers.
handler = urllib.request.HTTPBasicAuthHandler(password_mgr)
opener = urllib.request.build_opener(handler)
urllib.request.install_opener(opener)
# Connect to the server and read the response generated.
response = urllib.request.urlopen(search_url).read()
# Convert the bytes to a str. Because "The JSON object must be str, not 'bytes'"
str_response = response.decode('utf-8')
# Convert the string response to a Python dictionary object.
json_response = json.loads(str_response)
# Loop through each page returned, populating out results list.
for result in json_response['d']['results']:
results.append({
'title': result['Title'],
'link': result['Url'],
'summary': result['Description']
})
except urllib.request.URLError as e:
# Catch a URLError exception - something went wrong when connecting
print("Error when querying the Bing API: "+e)
return results
def main():
search_terms = input("Input the word you want to search>> ")
results = run_query(search_terms)
print("Rank"+' '+'Title'+50*' '+'URL')
rank = 0
for result in results:
rank += 1
print(str(rank).ljust(5), end=' ')
print(result['title'].ljust(50), end=' ')
print(result['link'])
if __name__ == '__main__':
main()