Kana iwe uri kuverenga chinyorwa ichi, iwe unogona kunge watojairana nemikana inovhura kana uchishandisa iyo API (Application Programming Interface).
Nekuwedzera imwe yeakawanda eruzhinji APIs kune yako application, unogona kuwedzera kushanda kweiyi application kana kuiwedzera neiyo data inodiwa. Asi ko kana wakagadzira chinhu chakasarudzika chaunoda kugovera nenharaunda?
Mhinduro iri nyore: unoda gadzira yako wega API.
ai_quotes = [
{
"id": 0,
"author": "Kevin Kelly",
"quote": "The business plans of the next 10,000 startups are easy to forecast: " +
"Take X and add AI."
},
{
"id": 1,
"author": "Stephen Hawking",
"quote": "The development of full artificial intelligence could " +
"spell the end of the human race⦠" +
"It would take off on its own, and re-design " +
"itself at an ever increasing rate. " +
"Humans, who are limited by slow biological evolution, " +
"couldn't compete, and would be superseded."
},
{
"id": 2,
"author": "Claude Shannon",
"quote": "I visualize a time when we will be to robots what " +
"dogs are to humans, " +
"and Iβm rooting for the machines."
},
{
"id": 3,
"author": "Elon Musk",
"quote": "The pace of progress in artificial intelligence " +
"(Iβm not referring to narrow AI) " +
"is incredibly fast. Unless you have direct " +
"exposure to groups like Deepmind, " +
"you have no idea how fast β it is growing " +
"at a pace close to exponential. " +
"The risk of something seriously dangerous " +
"happening is in the five-year timeframe." +
"10 years at most."
},
{
"id": 4,
"author": "Geoffrey Hinton",
"quote": "I have always been convinced that the only way " +
"to get artificial intelligence to work " +
"is to do the computation in a way similar to the human brain. " +
"That is the goal I have been pursuing. We are making progress, " +
"though we still have lots to learn about " +
"how the brain actually works."
},
{
"id": 5,
"author": "Pedro Domingos",
"quote": "People worry that computers will " +
"get too smart and take over the world, " +
"but the real problem is that they're too stupid " +
"and they've already taken over the world."
},
{
"id": 6,
"author": "Alan Turing",
"quote": "It seems probable that once the machine thinking " +
"method had started, it would not take long " +
"to outstrip our feeble powers⦠" +
"They would be able to converse " +
"with each other to sharpen their wits. " +
"At some stage therefore, we should " +
"have to expect the machines to take control."
},
{
"id": 7,
"author": "Ray Kurzweil",
"quote": "Artificial intelligence will reach " +
"human levels by around 2029. " +
"Follow that out further to, say, 2045, " +
"we will have multiplied the intelligence, " +
"the human biological machine intelligence " +
"of our civilization a billion-fold."
},
{
"id": 8,
"author": "Sebastian Thrun",
"quote": "Nobody phrases it this way, but I think " +
"that artificial intelligence " +
"is almost a humanities discipline. It's really an attempt " +
"to understand human intelligence and human cognition."
},
{
"id": 9,
"author": "Andrew Ng",
"quote": "We're making this analogy that AI is the new electricity." +
"Electricity transformed industries: agriculture, " +
"transportation, communication, manufacturing."
}
]
Ikozvino isu tinoda kugadzira Quote resource kirasi iyo inotsanangura mashandiro eiyo API endpoints. Nzira ina dzinofanirwa kuziviswa mukati mekirasi: tora, tumira, isa, bvisa.
Ngatitangei nenzira yeGET
Iyo inokutendera iwe kuti utore chaiyo quote nekutsanangura ID yayo, kana isingaite quote kana pasina ID inotsanangurwa.
class Quote(Resource):
def get(self, id=0):
if id == 0:
return random.choice(ai_quotes), 200
for quote in ai_quotes:
if(quote["id"] == id):
return quote, 200
return "Quote not found", 404
Iyo GET nzira inodzosa yakasarudzika quote kana ID iine iyo default kukosha, i.e. pakufonera iyo nzira ID haina kuiswa.
Kana ikaiswa, ipapo nzira yacho inotsvaga pakati pemakotesheni uye inowana iyo ine ID yakapihwa. Kana pasina chawanikwa, meseji "Quote haina kuwanikwa, 404" inoratidzwa.
Rangarira, iyo nzira inodzosa chimiro cheHTTP che200 kana chikumbiro chakabudirira uye 404 kana yekupinda isina kuwanikwa.
Zvino ngatigadzirei POST nzira yekuwedzera quote nyowani kune repository
Tevere, iwe unofanirwa kugadzira iyo GET AI Quote endpoint inoratidza isina kurongeka quote (kana iyo ID iri default) kana quote kune yakataurwa ID.
Kuti ugadzire pekupedzisira, unofanirwa kudzvanya bhatani re "Gadzira Endpoint".
Isu tinodzokorora maitiro aya kune mamwe ese maAPI endpoints. Ndizvo zvose! Makorokoto, wakaburitsa API yako!
Kana zvese zvikafamba zvakanaka, iyo API peji inotaridzika seizvi:
mhedziso
Muchikamu chino, takafamba kuburikidza nekugadzirisa kwekugadzira yedu RESTful API Service muPython, pamwe chete nehurongwa hwekudhindisa API kune gore reHeroku uye kuwedzera kune RapidAPI dhairekitori.
Asi muyedzo vhezheni, chete misimboti yekutanga yekuvandudza API yakaratidzwa - senge chengetedzo, kushivirira kukanganisa uye scalability hazvina kutariswa.
Paunenge uchigadzira API chaiyo, zvese izvi zvinofanirwa kuverengerwa.