How I access a REST web service I've created?
I've created a Rest Service as described here
Configured the webapplication as described in the previous link, and now have a URL which I call in PostMan
http://VIR-HC-DEV-01.gmmh.nhs.uk:52773/api/mgmnt/v2/parisconnect/PCRestWhich returns the JSON spec as I would expect:
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Swagger Petstore",
"description": "A sample API to demonstrate features in the swagger-2.0 specification",
"termsOfService": "http://swagger.io/terms/",
"contact": {
"name": "Swagger API Team"
},
"license": {
"name": "MIT"
}
},
"basePath": "/csp/healthshare/parisconnect",
"schemes": [
"http"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"/Messages": {
"get": {
"description": "Returns all messages the system handles",
"operationId": "Messages",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "A list of supported messages",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Message"
}
}
}
}
}
},
"/Hello": {
"get": {
"description": "Says Hello",
"operationId": "Hello",
"produces": [
"text/plain"
],
"responses": {
"200": {
"description": "Said hello",
"schema": {
"type": "string"
}
}
}
}
}
},
"definitions": {
"Message": {
"type": "object",
"required": [
"id",
"name",
"description"
],
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"tag": {
"type": "string"
}
}
}
},
"host": "VIR-HC-DEV-01.gmmh.nhs.uk:52773"
}I can use
http://localhost:52773/api/mgmnt/v2/Which returns
[
/*removed stuff*/
{
"name": "PCRest",
"dispatchClass": "PCRest.disp",
"namespace": "PARISCONNECT",
"swaggerSpec": "/api/mgmnt/v2/PARISCONNECT/PCRest"
}
]As you can see I have two messages which are defined in impl
/// A sample API to demonstrate features in the swagger-2.0 specification<br/>/// Business logic class defined by OpenAPI in PCRest.spec<br/>/// Updated Jan 21, 2024 15:15:01Class PCRest.impl Extends%REST.Impl [ ProcedureBlock ]
{
/// If ExposeServerExceptions is true, then details of internal errors will be exposed.Parameter ExposeServerExceptions = 0;/// Returns all messages the system handlesClassMethod Messages() As%DynamicObject
{
//(Place business logic here)Do ..%SetStatusCode("200")
//Do ..%SetHeader(<name>,<value>)//Quit (Place response here) ; response may be a string, stream or dynamic object#dim tJson as%Library.DynamicArrayset tJson = ##class(%Library.DynamicArray).%New()
do tJson.%Push("{""id"":""" _1_""", ""Name"": ""Name"", ""Description"": ""Description""}")
Quit tJson.%ToJSON()
}
/// Says HelloClassMethod Hello() As%Stream.Object
{
//(Place business logic here)Do ..%SetStatusCode("200")
//Do ..%SetHeader(<name>,<value>)//Quit (Place response here) ; response may be a string, stream or dynamic objectquit"Hello"
}
}
How do I go about calling the Hello message using postman? I've been all over the docs specified in the above, and can't find anything and feel I'm missing something?
The following GET post in Postman returns a 404
http://VIR-HC-DEV-01.gmmh.nhs.uk:52773/api/mgmnt/v2/PARISCONNECT/PCRest/HelloWhat am I doing wrong?
Comments
Hello @Andy Stobirski
Have you created a web application? If not, You have to create a web application. Configure the necessary details such as namespace, url add your PCRest.disp in dispatch class and assign roles. Save the application and call your RESTFul api from postman.
.png)
/// Says HelloClassMethod Hello() As%Stream.Object
{
return {"status":"ok","message":"working"}
}
.png)
Hi and thanks for your reply. I do have a webserver, but I didn't think to use it. It is configured as following
.png)
.png)
I haven't configured matching roles, though.
When I try to hit the URL
http://localhost:52773/v2/PARISCONNECT/PCRest/Hello
I get a 403 Forbidden, which is an improvement, but after fiddling with the settings I can't access it.
.png)
For testing purpose you can set the %ALL role and try test it again
Setting it to %ALL worked.
In postman, I'm using basic authorization and am using my standard username / password. That user has the roles %Developer and %EnsRole_Developer, so I'd have expected having those two roles assigned to Application Roles to work or am I misunderstanding how Application Roles work?
Your web application is configured to accept just Unauthenticated requests, if you want to use password authentication check it on the configuration.
I think that your application is ignoring the user that you are using and that's the reason because you don't have the proper permissions.
Of course! Thanks to you and your sharp eyes!