0

アプリにパブリック API を追加して、ユーザーが API 呼び出しを介してアプリケーションにアイテムを追加できるようにしようとしています。

なんかモヤモヤしますが……。

これまでのところ、すべてのモデルデータが非常に完璧な優れたxmlページを出力するこれがあります....

def index   
  @events = Event.all
  respond_to do |format|
    format.html 
    format.xml  { render :xml => @events }
    format.json { render :json => @events }
  end
end

だから私は、同じrespond_toブロックをCREATEまたはNEWアクション(どちらですか?)に追加して、そこで何らかの形のAPI機能を取得できると思いますか??? しかし、私はこのプロセス全体がどのように機能するかについて混乱しています...

たとえば、イベント モデルにフィールドが 1 つしかない場合 => name:string

Web サービスでレコードを追加するにはどうすればよいですか?

  ???? ==> curl http://localhost:3000/events[??????add??????]
4

1 に答える 1

1

cURLを使用したRESTアプリケーションのテストに関するこの投稿を参照してください。

引用:

-X [action]: Allows you to specify an HTTP action such as GET, POST, PUT or DELETE.
Example:

curl -X DELETE http://localhost:3000/books/1

-d [parameter]: Lets you set variables as if they were POSTed in a form to the URL. Note that this automatically makes the request a POST HTTP action type (no -X necessary).
Example:

curl -d "book[title]=Test" -d "book[copyright]=1998"
http://localhost:3000/books

-H [header]: Gives you the option of setting an HTTP header such as Content-Type or Accept. This is particularly useful for requesting text/xml as the Accept type.
Example:

curl -H "Accept: text/xml"
http://localhost:3000/books/sections/1
于 2012-06-26T18:26:34.780 に答える