我想实施有效的 Restful API
我有一个名为“Jobs”的资源,我还实现了CRUD [GET,POST,PUT ...],例如:DECLARE @Resultado TABLE (Row_ID BIGINT IDENTITY NOT NULL PRIMARY KEY, Inventory_Name VARCHAR(100), Transaction_Date DATETIME, DIRECTION BIT, Transaction_Name VARCHAR(100),Transaction_Quantity INT, Transaction_UnitCost NUMERIC(18,2), Transaction_Amount NUMERIC(18,2), AVERAGE_UNITCOST_AT_TRANSACTION_DATE NUMERIC(18,2))
INSERT INTO @Resultado ( Inventory_Name , Transaction_Date , DIRECTION , Transaction_Name , Transaction_Quantity , Transaction_UnitCost, Transaction_Amount, AVERAGE_UNITCOST_AT_TRANSACTION_DATE)
SELECT 'COMPUTER', '2017-01-01', 1, 'INCOMING PRODUCT; PRUCHASE', 100, 10, 100 * 10, 10
UNION ALL SELECT 'COMPUTER', '2017-01-02', 1, 'INCOMING PRODUCT; PURCHASE', 105, 11, 105 * 11, 10.51
UNION ALL SELECT 'COMPUTER', '2017-01-03', 1, 'INCOMING PRODUCT; PURCHASE', 110, 12, 110 * 12, 11.03
UNION ALL SELECT 'COMPUTER', '2017-01-04', 0, 'OUTGOING PRODUCT; SALES', -200, NULL, NULL, NULL
UNION ALL SELECT 'COMPUTER', '2017-01-05', 0, 'OUTGOING PRODUCT; SALES', -50, NULL, NULL, NULL
UNION ALL SELECT 'COMPUTER', '2017-01-06', 1, 'INCOMING PRODUCT; PURCHASE', 110, 10, 110 * 10, NULL
UNION ALL SELECT 'COMPUTER', '2017-01-07', 0, 'OUTGOING PRODUCT; SALES', -20, NULL, NULL, NULL
UNION ALL SELECT 'COMPUTER', '2017-01-08', 0, 'OUTGOING PRODUCT; SALES', -20, NULL, NULL, NULL
UNION ALL SELECT 'COMPUTER', '2017-01-09', 0, 'OUTGOING PRODUCT; SALES', -20, NULL, NULL, NULL
SELECT * FROM @Resultado
或GET: /api/jobs/1
现在我想添加一个方法来启动一个职位编号1234
我该如何实现呢?什么应该是URI?什么是HTTP动词?
有人可以举个例子吗
答案 0 :(得分:0)
您可以创建新资源
<!-- VMS Form -->
<div class="vms-form-container col-sm-8">
<div class="vms-form">
<div class="vms-form-title">
VENUE <span class="vms-form-title-bold">LOGIN</span>
</div>
<div class="vms-form-title-bottom-border"></div>
<div class="vms-form-inner">
<form>
<input type="text" name="email" placeholder="Email">
<input type="password" name="password" placeholder="Password">
<br>
<button type="submit" class="vms-form-submit">
LOGIN
<span>✔</span></div>
</button>
<a href="#!">> Forgot Password ? Reset</a>
</form>
</div>
</div>
<div class="vms-form-footer">
<a href="#!">
<img src="../images/vms/icon-vms-form-footer.png">
> or create an account
</a>
</div>
</div>
您可以内联编辑作业的状态:
POST /started-jobs?jobId=1234
您可以使用micro-PUT
PUT /jobs/1234
{
"state": "started",
..
}
这只是我的头脑。肯定还有其他选择。哪一个最好?这需要更多关于你想要完成的事情的信息。