Upgrade to Pro — share decks privately, control downloads, hide ads and more …

WP REST API 常見的使用方式,以 React 和 iOS 為例 / Create R...

WP REST API 常見的使用方式,以 React 和 iOS 為例 / Create React iOS App with WordPress REST API_縱裕 / Travis Chang

介紹如何使用 WP REST API 與前端技術和 iOS 手機 App 互動 。

WordCamp Taipei

December 28, 2019
Tweet

More Decks by WordCamp Taipei

Other Decks in Technology

Transcript

  1. WP REST API ଉ憎ጱֵአොୗ զ React ޾ iOS 傶ֺ WordCamp

    Taipei 2019 拻䒍: 婛ᤶ Progress bar 昲ଶ䬈娄Ӥ抓ᑕ
  2. WordPress 姜殷ኞ౮ 1. HTML ฎ奈෈ਁ㲌਻ 2. PHP ݢզኞ౮෈ਁ => ኞ౮HTML

    3. MySQL揾ා䓚ݢզ㱪ਂ෈ਁ揾ා 4. PHP ݢզℂMySQL೭ݐ෈ਁ揾ා 5. WordPressԆᥝฎኧPHP愚֢ᘒ౮
  3. AJAXฎՋἌ Asynchronous JavaScript and XML ᶋݶྍጱ JavaScript 岈 XML̶ ኧ姜殷

    JavaScript ᭐晃 BOM ඙֢倵懀࢏咳ڊ HTTP 我 㺔ᥝ࿢ک஍ᒒ֑๐࢏̶஍ᒒ֑๐࢏զ຤Ӟ圵揾ාࣳ䙪ࢧ䛑 JavaScript ᑕୗ̶ᑕୗݐ஑ࢧ䛑஍ٚ؉ፘ䌘䛑㵕֢ (ֺ ই DOM ඙֢)̶ 吚䦒 XML 揾ාࣳ䙪உၞᤈ҅֕匍ࣁ䓅Ԓᤩ JSON ݐդ̶
  4. Web API API => Application programming interface => 䛑አᑕୗՕᶎ Interface

    => Օᶎ => ݢ׀඙֢旉䟵೰ե̶ 斸ف A ද捧ԧ B 䌙ڊ C 奾ຎ ݢզమ౮Ӟ㮆㺠㵕ۑᚆጱೲ杴҅౲ฎ斸فՕᶎ
  5. URL 岈 Web API ଉ憎አ㬵 1. ݐ஑揾ාֺ҅ইݐ஑ಅํ෈ᒍ㲌਻
 https://yourdomain.com/getAllPosts 2. 䁆ᤈ೰եֺ҅ইੀᭆEmail


    https://yourdomain.com/sendEmail ӧݶጱURLդᤒӧݶጱ఺௏҅䁆ᤈӧݶጱ㲌 ਻҅昧ࢧ㯽໒ୗ᮷ݢᚆӧݶ

  6. REST API Resource Representational State Transfer 妞Ӟ໒ୗ҅ݢզ䓅ԒݢզፗളℂURLᎣ᭲ፓጱ̶ 1. URL ᪠䕩ړ㳨䌘䛑ک揾ා䓚ଉ憎㵕֢ғෛी

    捝ݐ ץද 㳫ᴻ̶᝕෈墋圸 CRUD, Create Read Update Delete
 2. Restful API ଉ憎ጱ㳷ํ҅Index, Show, Create, Update, Delete̶
  7. WordPress 毆戔ጱ API ֺৼ 1. /wp-json/wp/v2/posts
 捝ݐಅํ෈ᒍ 2. /wp-json/wp/v2/pages
 捝ݐಅํ殷ᶎ

    3. /wp-json/wp/v2/posts/42 
 捝ݐ id 42彚 ෈ᒍ
 
 च๜Ӥݝํ捝ݐ䷱ํ䌃ف
  8. Ջ焒ฎ React JS React JSฎᬪଙ㬵๋ၞᤈጱڹᒒ໛ຝԏӞ҅ኧ屜䨗 Facebookلݪಅ愚֢㪔Ӭզع揲ࠟአ樄რጱොୗ樄 නֵአ(MIT ദ䳷)̶ ReactJS ଉ憎ጱአ᭔叨ኞڊ԰㵕௔䮩֯ጱ

    Single Page Application (㻌殷ᶎ䛑አᑕୗ - SPA)̶捰ֵ አᘏࣁ䁆ᤈݱ圵姜殷ۑᚆ䦒ӧ䨝ࢩ傶᪡殷ᘒ୽段ֵአ ᘏ℆涢̶
  9. React ጱ䌕ໜ୵ୗ 1. 奈JavaScript ڹ஍ᒒړ櫝
 WordPress 傶 Web API Server

    2. ؉౮JavaScript UI ڍୗ䓚
 3. ؉౮WordPress Plugin
  10. WooCommerce API 䳷ᴴ㺔氂 1. ஠殾ᥝํconsumer key 岈 consumer secret҅Ԟ੪ฎᛗ੝ᥝ戢㲘 2.

    僻ဩ朼䌘㮆㳨ۑᚆ戔ਧ䳷ᴴ҅ݝํق樄 ق橕 3. 䳷ᴴ妔உय़҅昧懪㻌᮷ݢզ捝ݐ̶