Penguin Cho
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    1
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- title: Strapi 快速入門 tags: Strapi description: Strapi quick start! --- # 用Strapi 10分鐘就建好API(Strapi介紹-前篇) <!-- Put the link to this slide here so people can follow --> 來源: https://strapi.io/documentation/3.0.0-beta.x/getting-started/quick-start.html [前篇(快速入門)](https://hackmd.io/oXdEw-gBTSGheNsARMJYVg) [中篇(概念架構介紹)](https://hackmd.io/LqgfRVBXQf-OYFrvdiT7Hw) [後篇(部署及設定)](https://hackmd.io/-2zeYcrgR52aI-gssI-XFQ) :+1: 不用設定資料庫以及接觸後端程式,用Strapi就能為你的前端網頁快速建置好API !! --- ## Step 1. 在電腦上安裝Strapi ```javascript //cmd line npm install strapi@beta -g ``` <!-- --- --> ## Step 2. 使用指令快速新建你的Strapi專案 (此快速建置的流程中,預設的資料庫為SQLite,可以在指令中另外選擇) 路徑: **/my-project ```javascript //cmd line //my-project: 你的專案名稱 strapi new my-project --quickstart ``` ### 成功後自動開啟註冊頁面 註冊一個最高層級使用者的帳號(此為開發模式,可以放心測試,帳號隨便註冊都可以) ![](https://strapi.io/documentation/assets/img/strapi-welcome-screen.523da090.png) ### 註冊完成後就會看到admin儀表板頁面 ![](https://strapi.io/documentation/assets/img/AfterRegistrationScreenAdminPanel.3e52238b.png) --- ## Step 3. 建立和更新資料結構 Create a new Content Type 資料結構是擁有多個欄位以及資料的集合,接下來先新增Restaurant的資料結構試試看! ### 建立Restaurant的資料結構: 1. 新增資料結構: - 點擊右上角的 ==+增加資料結構== 的按鈕 - 在名稱中輸入 ==Restaurant== - 點擊 ==儲存== ![](https://strapi.io/documentation/assets/img/RestaurantNameAndDescription.c4a4bc9f.png) 2. 儲存之後,馬上就可以新增欄位(Restaurant, Description) #### 點擊右上的==新增欄位== #### 首先設定餐廳的名稱 - 點擊==字串== - 在**基本設定**中,==名稱==的輸入框輸入 Restaurant - 在**進階設定**中,勾選==必填欄位==以及==唯一欄位== - 點擊==繼續== ![](https://strapi.io/documentation/assets/img/restaurantAddFields.f968bd76.png) ![](https://strapi.io/documentation/assets/img/saveRestaurantNameField.8a21745d.png) ![](https://strapi.io/documentation/assets/img/restaurantAdvancedSettingsStringField.7551f2de.png) #### 接著設定餐廳的描述 - 點擊==文字== - 在**基本設定**中,==名稱==的輸入框輸入 Description - 在**進階設定**中,勾選==顯示視覺化編輯器(WYSIWYG)== - 點擊==儲存== ![](https://strapi.io/documentation/assets/img/restaurantTextFieldBaseSettings.b5e5eafa.png) ![](https://strapi.io/documentation/assets/img/restaurantTextFieldAdvancedSettings.8186eb3d.png) ![]() #### 點擊右上角的==儲存== ![](https://strapi.io/documentation/assets/img/saveRestaurantContentType.83396c6a.png) --- ### 建立Category的資料結構(返回建立和更新資料結構主頁面): 1. 新增資料結構: - 點擊右上角的 ==+增加資料結構== 的按鈕 - 在名稱中輸入 ==Category== - 點擊 ==儲存== ![](https://strapi.io/documentation/assets/img/categoryStringNameField.f1d13920.png) 2. 儲存之後,馬上就可以新增欄位(Category, 關聯) #### 點擊右上的==新增欄位== #### 首先設定Category的名稱 - 點擊==字串== - 在**基本設定**中,==名稱==的輸入框輸入 Category - 在**進階設定**中,勾選==必填欄位==以及==唯一欄位== - 點擊==繼續== ![](https://strapi.io/documentation/assets/img/categoryAddStringField.f1843843.png) ![](https://strapi.io/documentation/assets/img/categoryStringNameField.f1d13920.png) ![](https://strapi.io/documentation/assets/img/categoryStringAdvancedSettings.f974ef17.png) #### 接著設定Category的關聯 - 點擊==關聯== - 在**定義關係**中,==左邊的==的輸入框輸入 restaurant,==右邊的==User-Permissions改為選擇==Restaurant== - 中間很多條線的地方,選擇==最右邊的圖示==(多對多),Categories 有而且屬於許多 Restaurants - 點擊==儲存== ![](https://strapi.io/documentation/assets/img/clickRelationFieldCategory.4e04198f.png) ![](https://strapi.io/documentation/assets/img/categoryHasManyToMany.9b46c457.png) ![]() #### 點擊右上角的==儲存== ![](https://strapi.io/documentation/assets/img/nowSaveCategory.596b74d0.png) --- ## Step 4. 為各個資料結構增添一點內容吧! ### 1. Restaurants: 點擊左上角的Restaurants :::info 你沒看錯也沒有打錯字,Strapi會自動將資料結構名稱變為複數的單字 ::: - 在==Restaurant==中輸入`Strapi Restaurant` - 在==Description==中輸入`Strapi restaurant is a cosy restaurant delivering one of the very fastest and nicest dining experiences in the world, combining nods to tradition with fierce modernity, warmth with daring.` - 點擊右上角的==儲存== ![](https://strapi.io/documentation/assets/img/AddStrapiRestaurant.b012a7c3.png) ![](https://strapi.io/documentation/assets/img/addTheRestaurantData.904f217f.png) ### 2. Categories: 點擊左上角的Categories - 點擊右上角的==建立新的Category== - 在==Category==中輸入`Convenient` - 點擊右上角的==儲存== - 再新增一筆! - 在==Category==中輸入`Time Saving` - 點擊右上角的==儲存== - 將新增完的Categories,給Restaurant使用吧! - 點擊左上角回到Restaurant的頁面 - 點選其中一筆Restaurant的資料,並編輯他 - 在頁面右邊,Categories中,新增關聯 選擇你要與這筆資料關聯的category - 點擊右上角的==儲存== ![](https://strapi.io/documentation/assets/img/AddStrapiRestaurant.b012a7c3.png) ![](https://strapi.io/documentation/assets/img/addTheRestaurantData.904f217f.png) ![](https://strapi.io/documentation/assets/img/selectCategoryFromRestaurant.682bafbc.png) --- ## Step 5. 設定 角色與權限 :::warning :warning: 沒有設定此步驟,你將沒有權限使用API (403 forbidden) 備註: Strapi預設為關閉公開API的權限 ::: - 點擊左側擴充功能中的==身份與權限== - 點擊==Public== - 在權限區域中,將Restaurant以及Category的 ==find== ==findOne== 都勾選起來 - 點擊右上角的==儲存== ![](https://strapi.io/documentation/assets/img/rolesAndPermissions.ac9154c4.png) ![](https://strapi.io/documentation/assets/img/rolesFindAndRoute.62d22ecb.png) ## Step 6. 開心使用API~ ### 專案的網址為 `http://localhost:1337/` 接著你可以在網址後面加上像是 `/restaurants`來使用restaurants的API ```javascript http://localhost:1337/restaurants ``` ### :gift: 使用graphQL需要另外安裝插件 :::info 需在專案目錄下輸入以下指令來完成安裝graphQL ```javascript //cmd line strapi install graphql ``` 使用以下網址即可使用graphQL ```javascript http://localhost:1337/graphql ``` ::: :::warning :warning: strapi在develop環境下可以直接使用graphQL,然而production需要增加以下設定 - 檔案路徑: (沒有就自己建) ```javascript ./extensions/graphql/config/settings.json ``` ```javascript= { "endpoint": "/graphql", "tracing": false, "shadowCRUD": true, "playgroundAlways": true, "depthLimit": 7, "amountLimit": 100 } ``` :::

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully