Cloud9でAPIを作成しておりPostmanで動作確認がしたいが、URLがわかりません。
現在、薬の名前と分野を登録する、編集、削除等ができるAPIを作成しております。
その際、CRUDを作成し、ターミナル上では動作確認できましたが、Postmanにて動作確認をしたいと思い、つまづいております。
初学者のため、質問がわかりづらく、拙い点があるかと思います。申し訳ございません。
URLがわからないということは、そもそも理解が足りていないことは重々承知しております。
情報として足りない場所があれば、お教えください。
よろしくお願いします。
<調べたこと>
・「rails s」し、開いたページのURLに/api/v1/medicines/:idを付け加える。
・「rails server」をし、出てきたULに上記、同じように/api/v1/medicines/:idを付け加えてみる。
上記はAPI動作確認できず、Oopsが表示されるか、「リクエストを送信できませんでした」と表示される結果になりました。
<質問補足>
・入力するURLがわかるためにはどのようなデータが必要が教えていただけると幸いです。
以下に、必要と思ったものを貼り付けます。
api/vi/medicines_controller.rb
module Api module V1 class MedicinesController < ApplicationController before_action :set_medicine, only: [:show, :update, :destroy] # show(表示画面)、edit(編集画面)、update(更新画面)、destroy(削除画面)」が呼び出された際に、 # 事前処理として「set_medicine」を実行する def index medicines = Medicine.order(created_at: :desc) render json: { status: 'SUCCESS', message: 'Loaded medicine', data: medicines } end def show render json: { status: 'SUCCESS', message: 'Loaded the medicine', data: @medicine } end def create medicine = Medicine.new(medicine_params) if medicine.save render json: { status: 'SUCCESS', data: medicine } else render json: { status: 'ERROR', data: medicine.errors } end end def destroy @medicine.destroy render json: { status: 'SUCCESS', message: 'Deleted the medicine', data: @medicine } end def update if @medicine.update(medicine_params) render json: { status: 'SUCCESS', message: 'Updated the medicine', data: @medicine } else render json: { status: 'SUCCESS', message: 'Not updated', data: @medicine.errors } end end private def set_medicine @medicine = Medicine.find(params[:id]) end def medicine_params params.require(:medicine).permit(:medicine_name, :medicine_type) end end end end
以下 routesです、
loudUser:~/environment/railsapp (master) $ rails routes Prefix Verb URI Pattern Controller#Action api_v1_medicines GET /api/v1/medicines(.:format) api/v1/medicines#index POST /api/v1/medicines(.:format) api/v1/medicines#create api_v1_medicine GET /api/v1/medicines/:id(.:format) api/v1/medicines#show PATCH /api/v1/medicines/:id(.:format) api/v1/medicines#update PUT /api/v1/medicines/:id(.:format) api/v1/medicines#update DELETE /api/v1/medicines/:id(.:format) api/v1/medicines#destroy rails_postmark_inbound_emails POST /rails/action_mailbox/postmark/inbound_emails(.:format)
ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-linux]
Rails 6.1.4.4
Cloud9
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/06/16 10:40